mirror of
https://github.com/archtechx/jobpipeline.git
synced 2025-12-12 08:04:04 +00:00
Allow canceling pipelines by returning false from handle()
This commit is contained in:
parent
8fcac74f86
commit
86873515ae
4 changed files with 46 additions and 1 deletions
|
|
@ -75,6 +75,8 @@ class JobPipelineTest extends TestCase
|
|||
event(new TestEvent(new TestModel()));
|
||||
$this->artisan('queue:work --once');
|
||||
|
||||
sleep(1);
|
||||
|
||||
$this->assertSame('bar', $this->valuestore->get('foo'));
|
||||
}
|
||||
|
||||
|
|
@ -110,6 +112,27 @@ class JobPipelineTest extends TestCase
|
|||
|
||||
$this->assertSame(['a', 'b'], app('test_args'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function the_pipeline_can_be_canceled_by_returning_false_from_any_job()
|
||||
{
|
||||
Event::listen(TestEvent::class, JobPipeline::make([
|
||||
FalseJob::class,
|
||||
FooJob::class,
|
||||
])->send(function () {
|
||||
return $this->valuestore;
|
||||
})->shouldBeQueued(true)->toListener());
|
||||
|
||||
event(new TestEvent(new TestModel()));
|
||||
$this->artisan('queue:work --once');
|
||||
|
||||
sleep(1);
|
||||
|
||||
$this->assertTrue($this->valuestore->get('false_job_executed'));
|
||||
|
||||
// Foo job is not excuted
|
||||
$this->assertFalse($this->valuestore->has('foo'));
|
||||
}
|
||||
}
|
||||
|
||||
class FooJob
|
||||
|
|
@ -193,3 +216,20 @@ class JobWithMultipleArguments
|
|||
app()->instance('test_args', [$this->first, $this->second]);
|
||||
}
|
||||
}
|
||||
|
||||
class FalseJob
|
||||
{
|
||||
protected $valuestore;
|
||||
|
||||
public function __construct(Valuestore $valuestore)
|
||||
{
|
||||
$this->valuestore = $valuestore;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this->valuestore->put('false_job_executed', true);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
{"false_job_executed":true}
|
||||
Loading…
Add table
Add a link
Reference in a new issue