Skip to content

Commit b365dd5

Browse files
Support to specify the queue name based on the job. (#6538)
Co-authored-by: 李铭昕 <715557344@qq.com>
1 parent df50343 commit b365dd5

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/Functions.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
use Hyperf\AsyncQueue\Driver\DriverFactory;
1616
use Hyperf\Context\ApplicationContext;
1717

18-
function dispatch(JobInterface $job, ?int $delay = null, ?int $maxAttempts = null, ?string $pool = null): bool
18+
function dispatch(JobInterface $job, ?int $delay = null, ?int $maxAttempts = null, ?string $queue = null): bool
1919
{
2020
if (is_int($maxAttempts)) {
2121
$job->setMaxAttempts($maxAttempts);
2222
}
2323

24+
$queue ??= $job->getQueueName();
25+
2426
return ApplicationContext::getContainer()
2527
->get(DriverFactory::class)
26-
->get($pool ?? 'default')
28+
->get($queue)
2729
->push($job, $delay ?? 0);
2830
}

src/Job.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,9 @@ public function compress(): static
5757

5858
return $this;
5959
}
60+
61+
public function getQueueName(): string
62+
{
63+
return 'default';
64+
}
6065
}

src/JobInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ public function handle();
2626
public function setMaxAttempts(int $maxAttempts): static;
2727

2828
public function getMaxAttempts(): int;
29+
30+
public function getQueueName(): string;
2931
}

0 commit comments

Comments
 (0)