-
-
Notifications
You must be signed in to change notification settings - Fork 191
/
Copy pathQueueWorker.php
47 lines (40 loc) · 1.39 KB
/
QueueWorker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace Native\Laravel;
use Native\Laravel\Contracts\ChildProcess as ChildProcessContract;
use Native\Laravel\Contracts\QueueWorker as QueueWorkerContract;
use Native\Laravel\DTOs\QueueConfig;
class QueueWorker implements QueueWorkerContract
{
public function __construct(
private readonly ChildProcessContract $childProcess,
) {}
public function up(string|QueueConfig $config): void
{
if (is_string($config) && config()->has("nativephp.queue_workers.{$config}")) {
$config = QueueConfig::fromConfigArray([
$config => config("nativephp.queue_workers.{$config}"),
])[0];
}
if (! $config instanceof QueueConfig) {
throw new \InvalidArgumentException("Invalid queue configuration alias [$config]");
}
$this->childProcess->artisan(
[
'queue:work',
"--name={$config->alias}",
'--queue='.implode(',', $config->queuesToConsume),
"--memory={$config->memoryLimit}",
"--timeout={$config->timeout}",
],
'queue_'.$config->alias,
persistent: true,
iniSettings: [
'memory_limit' => "{$config->memoryLimit}M",
]
);
}
public function down(string $alias): void
{
$this->childProcess->stop('queue_'.$alias);
}
}