Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Commit

Permalink
Dispatch event for each started feature, operation and job
Browse files Browse the repository at this point in the history
  • Loading branch information
adiachenko committed Aug 21, 2019
1 parent f1be349 commit b299e07
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Events/FeatureStarted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Lucid\Foundation\Events;

class FeatureStarted
{
/**
* @var string
*/
public $name;

/**
* FeatureStarted constructor.
* @param string $name
*/
public function __construct($name)
{
$this->name = $name;
}
}
20 changes: 20 additions & 0 deletions src/Events/JobStarted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Lucid\Foundation\Events;

class JobStarted
{
/**
* @var string
*/
public $name;

/**
* JobStarted constructor.
* @param string $name
*/
public function __construct($name)
{
$this->name = $name;
}
}
20 changes: 20 additions & 0 deletions src/Events/OperationStarted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Lucid\Foundation\Events;

class OperationStarted
{
/**
* @var string
*/
public $name;

/**
* OperationStarted constructor.
* @param string $name
*/
public function __construct($name)
{
$this->name = $name;
}
}
9 changes: 9 additions & 0 deletions src/JobDispatcherTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Lucid\Foundation;

use Lucid\Foundation\Events\JobStarted;
use Lucid\Foundation\Events\OperationStarted;
use ReflectionClass;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -31,6 +33,13 @@ public function run($job, $arguments = [], $extra = [])
$job = $this->marshal($job, new Collection(), $arguments);
}

if ($job instanceof Operation) {
event(new OperationStarted(get_class($job)));
}
if ($job instanceof Job) {
event(new JobStarted(get_class($job)));
}

$result = $this->dispatch($job, $arguments);
}

Expand Down
3 changes: 3 additions & 0 deletions src/ServesFeaturesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Collection;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Lucid\Foundation\Events\FeatureStarted;

trait ServesFeaturesTrait
{
Expand All @@ -20,6 +21,8 @@ trait ServesFeaturesTrait
*/
public function serve($feature, $arguments = [])
{
event(new FeatureStarted($feature));

return $this->dispatch($this->marshal($feature, new Collection(), $arguments));
}
}

0 comments on commit b299e07

Please sign in to comment.