|
6 | 6 |
|
7 | 7 | use Illuminate\Support\Facades\DB; |
8 | 8 | use Illuminate\Support\Str; |
| 9 | +use Workflow\V2\Contracts\HistoryProjectionRole; |
9 | 10 | use Workflow\V2\Enums\ActivityAttemptStatus; |
10 | 11 | use Workflow\V2\Enums\ActivityStatus; |
11 | | -use Workflow\V2\Enums\HistoryEventType; |
12 | 12 | use Workflow\V2\Enums\TaskStatus; |
13 | 13 | use Workflow\V2\Enums\TaskType; |
14 | 14 | use Workflow\V2\Models\ActivityAttempt; |
15 | 15 | use Workflow\V2\Models\ActivityExecution; |
16 | | -use Workflow\V2\Models\WorkflowHistoryEvent; |
17 | 16 | use Workflow\V2\Models\WorkflowRun; |
18 | 17 | use Workflow\V2\Models\WorkflowTask; |
19 | 18 |
|
@@ -100,13 +99,13 @@ public static function claimDetailed( |
100 | 99 | $backendError = TaskBackendCapabilities::recordClaimFailureIfUnsupported($task); |
101 | 100 |
|
102 | 101 | if ($backendError !== null) { |
103 | | - RunSummaryProjector::project($run->fresh(['instance', 'tasks', 'activityExecutions', 'failures'])); |
| 102 | + self::historyProjectionRole()->projectRun(self::projectionRun($run)); |
104 | 103 |
|
105 | 104 | return self::claimFailure('backend_unsupported', null, $backendError); |
106 | 105 | } |
107 | 106 |
|
108 | 107 | if (! TaskCompatibility::supported($task, $run)) { |
109 | | - RunSummaryProjector::project($run->fresh(['instance', 'tasks', 'activityExecutions', 'failures'])); |
| 108 | + self::historyProjectionRole()->projectRun(self::projectionRun($run)); |
110 | 109 |
|
111 | 110 | return self::claimFailure( |
112 | 111 | 'compatibility_unsupported', |
@@ -170,29 +169,7 @@ public static function claimDetailed( |
170 | 169 | 'lease_expires_at' => $task->lease_expires_at, |
171 | 170 | ]); |
172 | 171 |
|
173 | | - $parallelMetadataPath = ParallelChildGroup::metadataPathForSequence($run, (int) $execution->sequence); |
174 | | - $parallelMetadata = ParallelChildGroup::payloadForPath($parallelMetadataPath); |
175 | | - |
176 | | - WorkflowHistoryEvent::record($run, HistoryEventType::ActivityStarted, array_merge([ |
177 | | - 'activity_execution_id' => $execution->id, |
178 | | - 'activity_attempt_id' => $attemptId, |
179 | | - 'activity_class' => $execution->activity_class, |
180 | | - 'activity_type' => $execution->activity_type, |
181 | | - 'sequence' => $execution->sequence, |
182 | | - 'attempt_number' => $attemptCount, |
183 | | - 'activity' => ActivitySnapshot::fromExecution($execution), |
184 | | - ], $parallelMetadata ?? []), $task); |
185 | | - |
186 | | - LifecycleEventDispatcher::activityStarted( |
187 | | - $run, |
188 | | - (string) $execution->id, |
189 | | - (string) ($execution->activity_type ?? $execution->activity_class), |
190 | | - (string) $execution->activity_class, |
191 | | - (int) $execution->sequence, |
192 | | - $attemptCount, |
193 | | - ); |
194 | | - |
195 | | - RunSummaryProjector::project($run->fresh(['instance', 'tasks', 'activityExecutions', 'failures'])); |
| 172 | + self::historyProjectionRole()->recordActivityStarted($run, $execution, $attempt, $task); |
196 | 173 |
|
197 | 174 | return self::claimSuccess(new ActivityTaskClaim($task, $run, $execution, $attempt)); |
198 | 175 | }); |
@@ -249,6 +226,19 @@ private static function releaseDelaySeconds(WorkflowTask $task): int |
249 | 226 | return (int) ceil($remainingMilliseconds / 1000); |
250 | 227 | } |
251 | 228 |
|
| 229 | + private static function historyProjectionRole(): HistoryProjectionRole |
| 230 | + { |
| 231 | + /** @var HistoryProjectionRole $role */ |
| 232 | + $role = app(HistoryProjectionRole::class); |
| 233 | + |
| 234 | + return $role; |
| 235 | + } |
| 236 | + |
| 237 | + private static function projectionRun(WorkflowRun $run): WorkflowRun |
| 238 | + { |
| 239 | + return $run->fresh(['instance', 'tasks', 'activityExecutions', 'failures']) ?? $run; |
| 240 | + } |
| 241 | + |
252 | 242 | private static function nonEmptyString(mixed $value): ?string |
253 | 243 | { |
254 | 244 | return is_string($value) && $value !== '' |
|
0 commit comments