mirror of
https://github.com/archtechx/jobpipeline.git
synced 2025-12-12 09:34:04 +00:00
Add the ability to use closures inside pipelines
This commit is contained in:
parent
86873515ae
commit
f86e55ace7
3 changed files with 23 additions and 2 deletions
|
|
@ -57,7 +57,11 @@ class JobPipeline implements ShouldQueue
|
|||
public function handle(): void
|
||||
{
|
||||
foreach ($this->jobs as $job) {
|
||||
$result = app()->call([new $job(...$this->passable), 'handle']);
|
||||
if (is_string($job)) {
|
||||
$job = [new $job(...$this->passable), 'handle'];
|
||||
}
|
||||
|
||||
$result = app()->call($job);
|
||||
|
||||
if ($result === false) {
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -133,6 +133,24 @@ class JobPipelineTest extends TestCase
|
|||
// Foo job is not excuted
|
||||
$this->assertFalse($this->valuestore->has('foo'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function closures_can_be_used_as_jobs()
|
||||
{
|
||||
$passes = false;
|
||||
|
||||
Event::listen(TestEvent::class, JobPipeline::make([
|
||||
function (TestModel $model) use (&$passes) {
|
||||
$passes = $model instanceof TestModel;
|
||||
}
|
||||
])->send(function (TestEvent $event) {
|
||||
return $event->testModel;
|
||||
})->toListener());
|
||||
|
||||
event(new TestEvent(new TestModel()));
|
||||
|
||||
$this->assertTrue($passes);
|
||||
}
|
||||
}
|
||||
|
||||
class FooJob
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
{"false_job_executed":true}
|
||||
Loading…
Add table
Add a link
Reference in a new issue