Skip to content

Commit 1ea7c85

Browse files
Tag activity exceptions for probe replay
1 parent f3a5175 commit 1ea7c85

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

src/Activity.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ public function failed(Throwable $throwable): void
170170
$this->storedWorkflow,
171171
$throwable,
172172
$workflow->connection(),
173-
$workflow->queue()
173+
$workflow->queue(),
174+
$this::class
174175
);
175176
}
176177

tests/Unit/ExceptionTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
use Exception as BaseException;
88
use InvalidArgumentException;
99
use RuntimeException;
10+
use Tests\Fixtures\TestActivity;
1011
use Tests\Fixtures\TestProbeBackToBackWorkflow;
1112
use Tests\Fixtures\TestProbeChildFailureWorkflow;
1213
use Tests\Fixtures\TestProbeParallelChildWorkflow;
1314
use Tests\Fixtures\TestProbeRetryActivity;
15+
use Tests\Fixtures\TestSagaActivity;
16+
use Tests\Fixtures\TestSagaParallelActivityWorkflow;
1417
use Tests\Fixtures\TestWorkflow;
1518
use Tests\TestCase;
1619
use Workflow\Exception;
@@ -115,4 +118,45 @@ public function testPersistsWriteWhenProbeReachesCandidateException(): void
115118

116119
$this->assertTrue($storedWorkflow->fresh()->hasLogByIndex(1));
117120
}
121+
122+
public function testSkipsWriteWhenProbeReachesDifferentActivityClassAtSameIndex(): void
123+
{
124+
$workflow = WorkflowStub::load(WorkflowStub::make(TestSagaParallelActivityWorkflow::class)->id());
125+
$storedWorkflow = StoredWorkflow::findOrFail($workflow->id());
126+
$storedWorkflow->update([
127+
'arguments' => Serializer::serialize([]),
128+
'status' => WorkflowRunningStatus::$name,
129+
]);
130+
131+
$storedWorkflow->logs()
132+
->create([
133+
'index' => 0,
134+
'now' => now()
135+
->toDateTimeString(),
136+
'class' => TestActivity::class,
137+
'result' => Serializer::serialize('step complete'),
138+
]);
139+
140+
$storedWorkflow->logs()
141+
->create([
142+
'index' => 1,
143+
'now' => now()
144+
->toDateTimeString(),
145+
'class' => Exception::class,
146+
'result' => Serializer::serialize([
147+
'class' => RuntimeException::class,
148+
'message' => 'parallel failure',
149+
'code' => 0,
150+
]),
151+
]);
152+
153+
$exception = new Exception(2, now()->toDateTimeString(), $storedWorkflow, [
154+
'class' => RuntimeException::class,
155+
'message' => 'another parallel failure',
156+
'code' => 0,
157+
], sourceClass: TestSagaActivity::class);
158+
$exception->handle();
159+
160+
$this->assertFalse($storedWorkflow->fresh()->hasLogByIndex(2));
161+
}
118162
}

0 commit comments

Comments
 (0)