File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -127,8 +127,12 @@ public function active(): self
127127 $ active = $ this ->fresh ();
128128
129129 if ($ active ->status ::class === WorkflowContinuedStatus::class) {
130- $ active = $ this ->activeWorkflow ()
130+ $ continued = $ this ->activeWorkflow ()
131131 ->first ();
132+
133+ if ($ continued !== null ) {
134+ $ active = $ continued ;
135+ }
132136 }
133137
134138 return $ active ;
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Tests \Feature ;
6+
7+ use Tests \Fixtures \TestBatchContinueAsNewWorkflow ;
8+ use Tests \TestCase ;
9+ use Workflow \States \WorkflowCompletedStatus ;
10+ use Workflow \WorkflowStub ;
11+
12+ final class ContinueAsNewBatchWorkflowTest extends TestCase
13+ {
14+ public function testBatchActivitiesWithContinueAsNew (): void
15+ {
16+ $ workflow = WorkflowStub::make (TestBatchContinueAsNewWorkflow::class);
17+
18+ $ workflow ->start (20 );
19+
20+ while ($ workflow ->running ());
21+
22+ $ this ->assertEquals (WorkflowCompletedStatus::class, $ workflow ->status ());
23+ $ this ->assertIsArray ($ workflow ->output ());
24+ $ this ->assertCount (20 , $ workflow ->output ());
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Tests \Fixtures ;
6+
7+ use Workflow \Activity ;
8+
9+ class ProcessRecordActivity extends Activity
10+ {
11+ public function execute (): array
12+ {
13+ return [
14+ 'status ' => 'done ' ,
15+ ];
16+ }
17+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Tests \Fixtures ;
6+
7+ use Workflow \ActivityStub ;
8+ use Workflow \Workflow ;
9+ use Workflow \WorkflowStub ;
10+
11+ class TestBatchContinueAsNewWorkflow extends Workflow
12+ {
13+ public function execute (int $ maxResults = 20 , array $ results = [])
14+ {
15+ while (count ($ results ) < $ maxResults ) {
16+ $ activities = [
17+ ActivityStub::make (ProcessRecordActivity::class),
18+ ActivityStub::make (ProcessRecordActivity::class),
19+ ActivityStub::make (ProcessRecordActivity::class),
20+ ActivityStub::make (ProcessRecordActivity::class),
21+ ];
22+
23+ $ results = array_merge ($ results , yield ActivityStub::all ($ activities ));
24+
25+ return yield WorkflowStub::continueAsNew ($ maxResults , $ results );
26+ }
27+
28+ return $ results ;
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments