forked from codeigniter4/queue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.php
More file actions
154 lines (133 loc) · 3.57 KB
/
Queue.php
File metadata and controls
154 lines (133 loc) · 3.57 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
declare(strict_types=1);
/**
* This file is part of CodeIgniter Queue.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Queue\Config;
use CodeIgniter\Config\BaseConfig;
use CodeIgniter\Queue\Exceptions\QueueException;
use CodeIgniter\Queue\Handlers\DatabaseHandler;
use CodeIgniter\Queue\Handlers\PredisHandler;
use CodeIgniter\Queue\Handlers\RabbitMQHandler;
use CodeIgniter\Queue\Handlers\RedisHandler;
use CodeIgniter\Queue\Interfaces\JobInterface;
use CodeIgniter\Queue\Interfaces\QueueInterface;
class Queue extends BaseConfig
{
/**
* Default handler.
*/
public string $defaultHandler = 'database';
/**
* Available handlers.
*
* @var array<string, class-string<QueueInterface>>
*/
public array $handlers = [
'database' => DatabaseHandler::class,
'redis' => RedisHandler::class,
'predis' => PredisHandler::class,
'rabbitmq' => RabbitMQHandler::class,
];
/**
* Database handler config.
*/
public array $database = [
'dbGroup' => 'default',
'getShared' => true,
// use skip locked feature to maintain concurrency calls
// this is not relevant for the SQLite3 database driver
'skipLocked' => true,
];
/**
* Redis handler config.
*/
public array $redis = [
'host' => '127.0.0.1',
'password' => null,
'port' => 6379,
'timeout' => 0,
'database' => 0,
'prefix' => '',
];
/**
* Predis handler config.
*/
public array $predis = [
'scheme' => 'tcp',
'host' => '127.0.0.1',
'password' => null,
'port' => 6379,
'timeout' => 5,
'database' => 0,
'prefix' => '',
];
/**
* RabbitMQ handler config.
*/
public array $rabbitmq = [
'host' => '127.0.0.1',
'port' => 5672,
'user' => 'guest',
'password' => 'guest',
'vhost' => '/',
];
/**
* Whether to keep the DONE jobs in the queue.
*/
public bool $keepDoneJobs = false;
/**
* Whether to save failed jobs for later review.
*/
public bool $keepFailedJobs = true;
/**
* Default priorities for the queue
* if different from the "default".
*/
public array $queueDefaultPriority = [];
/**
* Valid priorities in the order for the queue,
* if different from the "default".
*/
public array $queuePriorities = [];
/**
* Your jobs handlers.
*
* @var array<string, class-string<JobInterface>>
*/
public array $jobHandlers = [];
public function __construct()
{
parent::__construct();
if (ENVIRONMENT === 'testing') {
$this->database['dbGroup'] = config('database')->defaultGroup;
}
}
/**
* Resolve job class name.
*
* @return class-string<JobInterface>
*/
public function resolveJobClass(string $name): string
{
if (! isset($this->jobHandlers[$name])) {
throw QueueException::forIncorrectJobHandler();
}
return $this->jobHandlers[$name];
}
/**
* Stringify queue priorities.
*/
public function getQueuePriorities(string $name): ?string
{
if (! isset($this->queuePriorities[$name])) {
return null;
}
return implode(',', $this->queuePriorities[$name]);
}
}