-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathWorkerCommand.php
More file actions
66 lines (54 loc) · 1.56 KB
/
WorkerCommand.php
File metadata and controls
66 lines (54 loc) · 1.56 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
declare(strict_types=1);
namespace Bow\Console\Command;
use Bow\Console\AbstractCommand;
use Bow\Queue\WorkerService;
class WorkerCommand extends AbstractCommand
{
/**
* The run server command
*
* @param string|null $connection
* @return void
*/
public function run(?string $connection = null): void
{
$tries = (int) $this->arg->getParameter('--tries', 3);
$default = $this->arg->getParameter('--queue', "default");
$memory = (int) $this->arg->getParameter('--memory', 126);
$timout = (int) $this->arg->getParameter('--timout', 3);
$sleep = (int) $this->arg->getParameter('--sleep', 60);
$queue = app("queue");
if (!is_null($connection)) {
$queue->setConnection($connection);
}
$worker = $this->getWorderService();
$worker->setConnection($queue->getAdapter());
$worker->run($default, $tries, $sleep, $timout, $memory);
}
/**
* Get the worker service
*
* @return WorkerService
*/
private function getWorderService()
{
return new WorkerService();
}
/**
* Flush the queue
*
* @param ?string $connection
* @return void
*/
public function flush(?string $connection = null)
{
$connection_queue = $this->arg->getParameter('--queue');
$queue = app("queue");
if (!is_null($connection)) {
$queue->setConnection($connection);
}
$adapter = $queue->getAdapter();
$adapter->flush($connection_queue);
}
}