@@ -128,14 +128,20 @@ public function handle(): void
128128 ->wherePivot ('parent_index ' , '!= ' , StoredWorkflow::ACTIVE_WORKFLOW_INDEX )
129129 ->first ();
130130
131- $ log = $ this ->storedWorkflow ->logs ()
132- ->whereIndex ($ this ->index )
131+ $ logs = $ this ->storedWorkflow ->logs ()
132+ ->whereIn ('index ' , [$ this ->index , $ this ->index + 1 ])
133+ ->get ();
134+
135+ $ log = $ logs ->where ('index ' , $ this ->index )
136+ ->first ();
137+
138+ $ nextLog = $ logs ->where ('index ' , $ this ->index + 1 )
133139 ->first ();
134140
135141 $ this ->storedWorkflow
136142 ->signals ()
137- ->when ($ log , static function ($ query , $ log ): void {
138- $ query ->where ('created_at ' , '<= ' , $ log ->created_at ->format ('Y-m-d H:i:s.u ' ));
143+ ->when ($ nextLog , static function ($ query , $ nextLog ): void {
144+ $ query ->where ('created_at ' , '<= ' , $ nextLog ->created_at ->format ('Y-m-d H:i:s.u ' ));
139145 })
140146 ->each (function ($ signal ): void {
141147 $ this ->{$ signal ->method }(...Serializer::unserialize ($ signal ->arguments ));
@@ -163,8 +169,14 @@ public function handle(): void
163169 while ($ this ->coroutine ->valid ()) {
164170 $ this ->index = WorkflowStub::getContext ()->index ;
165171
166- $ nextLog = $ this ->storedWorkflow ->logs ()
167- ->whereIndex ($ this ->index )
172+ $ logs = $ this ->storedWorkflow ->logs ()
173+ ->whereIn ('index ' , [$ this ->index , $ this ->index + 1 ])
174+ ->get ();
175+
176+ $ log = $ logs ->where ('index ' , $ this ->index )
177+ ->first ();
178+
179+ $ nextLog = $ logs ->where ('index ' , $ this ->index + 1 )
168180 ->first ();
169181
170182 if ($ log ) {
@@ -179,8 +191,6 @@ public function handle(): void
179191 });
180192 }
181193
182- $ log = $ nextLog ;
183-
184194 $ this ->now = $ log ? $ log ->now : Carbon::now ();
185195
186196 WorkflowStub::setContext ([
0 commit comments