Skip to content

Commit 797c990

Browse files
committed
Add ability to specify queue connection and name
1 parent 61db4c7 commit 797c990

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

config/metrics.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414
|
1515
*/
1616

17-
'queue' => env('METRICS_QUEUE', false),
17+
'queue' => env('METRICS_QUEUE', false) ? [
18+
'connection' => env('QUEUE_CONNECTION', 'sync'),
19+
'queue' => null,
20+
] : false,
1821
];

src/DatabaseMetricManager.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ public function commit(): void
4545
}
4646

4747
if ($queue = config('metrics.queue')) {
48-
CommitMetrics::dispatch($metrics, $queue);
48+
CommitMetrics::dispatch($metrics)
49+
->onQueue($queue['queue'] ?? null)
50+
->onConnection($queue['connection'] ?? null);
4951
} else {
50-
(new CommitMetrics($metrics, $queue))->handle();
52+
(new CommitMetrics($metrics))->handle();
5153
}
5254

5355
$this->repository->flush();

src/Jobs/CommitMetrics.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
use Illuminate\Bus\Queueable;
77
use Illuminate\Contracts\Queue\ShouldQueue;
88
use Illuminate\Foundation\Bus\Dispatchable;
9+
use Illuminate\Queue\InteractsWithQueue;
910
use Illuminate\Support\Collection;
1011

1112
class CommitMetrics implements ShouldQueue
1213
{
13-
use Dispatchable, Queueable;
14+
use Dispatchable, InteractsWithQueue, Queueable;
1415

1516
/**
1617
* Constructor.
1718
*/
1819
public function __construct(
1920
public array $metrics,
20-
public bool $shouldQueue,
2121
) {}
2222

2323
/**
@@ -38,8 +38,10 @@ public function handle(): void
3838
]));
3939
})
4040
->each(function (Collection $metrics) {
41-
if ($this->shouldQueue) {
42-
RecordMetric::dispatch($metrics);
41+
if (isset($this->job)) {
42+
RecordMetric::dispatch($metrics)
43+
->onQueue($this->queue)
44+
->onConnection($this->connection);
4345
} else {
4446
(new RecordMetric($metrics))->handle();
4547
}

0 commit comments

Comments
 (0)