Skip to content

Commit cc59c48

Browse files
Use workflow bridge filters for typed worker polling
Use workflow bridge filters for typed worker polling
1 parent 0a1420f commit cc59c48

2 files changed

Lines changed: 40 additions & 41 deletions

File tree

app/Support/WorkflowTaskPoller.php

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ private function claimReadyTask(
430430
limit: $limit,
431431
compatibility: null,
432432
namespace: $namespace,
433+
workflowTypes: $supportedWorkflowTypes,
433434
);
434435

435436
\Log::info('[WorkflowTaskPoller] claimReadyTask called', [
@@ -482,16 +483,6 @@ private function claimReadyTask(
482483
continue;
483484
}
484485

485-
if (! $this->matchesWorkflowType($supportedWorkflowTypes, $readyTask['workflow_type'] ?? null)) {
486-
\Log::debug('[WorkflowTaskPoller] Skipping task: workflow type not supported', [
487-
'taskId' => $readyTask['task_id'] ?? null,
488-
'taskWorkflowType' => $readyTask['workflow_type'] ?? null,
489-
'supportedWorkflowTypes' => $supportedWorkflowTypes,
490-
]);
491-
492-
continue;
493-
}
494-
495486
$taskId = is_string($readyTask['task_id'] ?? null)
496487
? $readyTask['task_id']
497488
: null;
@@ -620,34 +611,6 @@ private function matchesCompatibility(?string $buildId, mixed $compatibility): b
620611
return $buildId !== null && $compatibility === $buildId;
621612
}
622613

623-
/**
624-
* @param list<string> $supportedTypes
625-
*/
626-
/**
627-
* Check if a task's workflow type matches the worker's supported types.
628-
*
629-
* - If worker supports all types (empty list), match any task
630-
* - If worker supports specific types, only match tasks with those types
631-
* - Tasks with missing/empty workflow_type only match "all types" workers
632-
*
633-
* @param list<string> $supportedTypes
634-
*/
635-
private function matchesWorkflowType(array $supportedTypes, mixed $workflowType): bool
636-
{
637-
// Worker supports all workflow types
638-
if ($supportedTypes === []) {
639-
return true;
640-
}
641-
642-
// Task has no workflow type - only matches workers that accept all types
643-
if (! is_string($workflowType) || trim($workflowType) === '') {
644-
return false;
645-
}
646-
647-
// Check if task's workflow type is in worker's supported list
648-
return in_array($workflowType, $supportedTypes, true);
649-
}
650-
651614
private function nextVisibleReadyAt(string $namespace, string $taskQueue, ?string $buildId): ?\DateTimeInterface
652615
{
653616
$query = NamespaceWorkflowScope::taskQuery($namespace)

tests/Feature/WorkflowWorkerProtocolTest.php

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ public function test_it_uses_a_server_local_lease_counter_for_workflow_task_atte
578578
): void {
579579
$mock->shouldReceive('poll')
580580
->times(2)
581-
->with(null, 'external-workflows', 10, null, 'default')
581+
->with(null, 'external-workflows', 10, null, 'default', [])
582582
->andReturn(
583583
[[
584584
'task_id' => $task->id,
@@ -1390,7 +1390,7 @@ public function test_it_drops_claimed_workflow_tasks_when_the_bridge_cannot_buil
13901390
$this->mock(WorkflowTaskBridge::class, function (MockInterface $mock) use ($recordedAt): void {
13911391
$mock->shouldReceive('poll')
13921392
->once()
1393-
->with(null, 'external-workflows', 10, null, 'default')
1393+
->with(null, 'external-workflows', 10, null, 'default', [])
13941394
->andReturn([
13951395
[
13961396
'task_id' => 'wf-task-missing-row',
@@ -1461,7 +1461,7 @@ public function test_it_does_not_fall_back_to_a_local_ready_scan_when_the_workfl
14611461
$this->mock(WorkflowTaskBridge::class, function (MockInterface $mock): void {
14621462
$mock->shouldReceive('poll')
14631463
->once()
1464-
->with(null, 'external-workflows', 10, null, 'default')
1464+
->with(null, 'external-workflows', 10, null, 'default', [])
14651465
->andReturn([]);
14661466
});
14671467

@@ -1476,6 +1476,42 @@ public function test_it_does_not_fall_back_to_a_local_ready_scan_when_the_workfl
14761476
->assertJsonPath('task', null);
14771477
}
14781478

1479+
public function test_it_passes_supported_workflow_types_to_the_workflow_bridge_poll(): void
1480+
{
1481+
Queue::fake();
1482+
1483+
$this->configureWorkflowTypes();
1484+
$this->createNamespace('default', 'Default namespace');
1485+
1486+
$this->mock(WorkflowTaskBridge::class, function (MockInterface $mock): void {
1487+
$mock->shouldReceive('poll')
1488+
->once()
1489+
->with(
1490+
null,
1491+
'external-workflows',
1492+
10,
1493+
null,
1494+
'default',
1495+
['tests.external-greeting-workflow'],
1496+
)
1497+
->andReturn([]);
1498+
});
1499+
1500+
$this->registerWorker(
1501+
'php-worker-typed-bridge',
1502+
'external-workflows',
1503+
supportedWorkflowTypes: ['tests.external-greeting-workflow'],
1504+
);
1505+
1506+
$this->withHeaders($this->workerHeaders())
1507+
->postJson('/api/worker/workflow-tasks/poll', [
1508+
'worker_id' => 'php-worker-typed-bridge',
1509+
'task_queue' => 'external-workflows',
1510+
])
1511+
->assertOk()
1512+
->assertJsonPath('task', null);
1513+
}
1514+
14791515
public function test_it_passes_the_next_visible_workflow_task_deadline_into_long_polling(): void
14801516
{
14811517
Queue::fake();

0 commit comments

Comments
 (0)