Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
AbstractAdapter | |
100.00% |
10 / 10 |
|
100.00% |
7 / 7 |
9 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
setPriority | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
getPriority | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isFifo | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isFilo | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isLilo | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isLifo | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getStart | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getEnd | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getStatus | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
push | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
pop | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
hasJobs | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
hasFailedJob | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getFailedJob | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
hasFailedJobs | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getFailedJobs | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
clearFailed | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
clear | n/a |
0 / 0 |
n/a |
0 / 0 |
0 |
1 | <?php |
2 | /** |
3 | * Pop PHP Framework (http://www.popphp.org/) |
4 | * |
5 | * @link https://github.com/popphp/popphp-framework |
6 | * @author Nick Sagona, III <dev@nolainteractive.com> |
7 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
8 | * @license http://www.popphp.org/license New BSD License |
9 | */ |
10 | |
11 | /** |
12 | * @namespace |
13 | */ |
14 | namespace Pop\Queue\Adapter; |
15 | |
16 | use Pop\Queue\Queue; |
17 | use Pop\Queue\Process\Task; |
18 | use Pop\Queue\Process\AbstractJob; |
19 | |
20 | /** |
21 | * Adapter abstract class |
22 | * |
23 | * @category Pop |
24 | * @package Pop\Queue |
25 | * @author Nick Sagona, III <dev@nolainteractive.com> |
26 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
27 | * @license http://www.popphp.org/license New BSD License |
28 | * @version 2.0.0 |
29 | */ |
30 | abstract class AbstractAdapter implements AdapterInterface |
31 | { |
32 | |
33 | /** |
34 | * Queue type |
35 | * @var string |
36 | */ |
37 | protected string $priority = 'FIFO'; |
38 | |
39 | /** |
40 | * Constructor |
41 | * |
42 | * Instantiate the adapter object |
43 | * |
44 | * @param ?string $priority |
45 | */ |
46 | public function __construct(?string $priority = null) |
47 | { |
48 | if ($priority !== null) { |
49 | $this->setPriority($priority); |
50 | } |
51 | } |
52 | |
53 | /** |
54 | * Set queue priority |
55 | * |
56 | * @param string $priority |
57 | * @return AbstractAdapter |
58 | */ |
59 | public function setPriority(string $priority = 'FIFO'): AbstractAdapter |
60 | { |
61 | if (defined('Pop\Queue\Queue::' . $priority)) { |
62 | $this->priority = $priority; |
63 | } |
64 | return $this; |
65 | } |
66 | |
67 | /** |
68 | * Get queue priority |
69 | * |
70 | * @return string |
71 | */ |
72 | public function getPriority(): string |
73 | { |
74 | return $this->priority; |
75 | } |
76 | |
77 | /** |
78 | * Is FIFO |
79 | * |
80 | * @return bool |
81 | */ |
82 | public function isFifo(): bool |
83 | { |
84 | return ($this->priority == Queue::FIFO); |
85 | } |
86 | |
87 | /** |
88 | * Is FILO |
89 | * |
90 | * @return bool |
91 | */ |
92 | public function isFilo(): bool |
93 | { |
94 | return ($this->priority == Queue::FILO); |
95 | } |
96 | |
97 | /** |
98 | * Is LILO (alias to FIFO) |
99 | * |
100 | * @return bool |
101 | */ |
102 | public function isLilo(): bool |
103 | { |
104 | return ($this->priority == Queue::FIFO); |
105 | } |
106 | |
107 | /** |
108 | * Is LIFO (alias to FILO) |
109 | * |
110 | * @return bool |
111 | */ |
112 | public function isLifo(): bool |
113 | { |
114 | return ($this->priority == Queue::FILO); |
115 | } |
116 | |
117 | /** |
118 | * Get queue start index |
119 | * |
120 | * @return int |
121 | */ |
122 | abstract public function getStart(): int; |
123 | |
124 | /** |
125 | * Get queue end index |
126 | * |
127 | * @return int |
128 | */ |
129 | abstract public function getEnd(): int; |
130 | |
131 | /** |
132 | * Get queue job status |
133 | * |
134 | * @param int $index |
135 | * @return int |
136 | */ |
137 | abstract public function getStatus(int $index): int; |
138 | |
139 | /** |
140 | * Push job on to queue |
141 | * |
142 | * @param AbstractJob $job |
143 | * @return AdapterInterface |
144 | */ |
145 | abstract public function push(AbstractJob $job): AdapterInterface; |
146 | |
147 | /** |
148 | * Pop job off of queue |
149 | * |
150 | * @return ?AbstractJob |
151 | */ |
152 | abstract public function pop(): ?AbstractJob; |
153 | |
154 | /** |
155 | * Check if adapter has jobs |
156 | * |
157 | * @return bool |
158 | */ |
159 | abstract public function hasJobs(): bool; |
160 | |
161 | /** |
162 | * Check if adapter has failed job |
163 | * |
164 | * @param int $index |
165 | * @return bool |
166 | */ |
167 | abstract public function hasFailedJob(int $index): bool; |
168 | |
169 | /** |
170 | * Get failed job |
171 | * |
172 | * @param int $index |
173 | * @param bool $unserialize |
174 | * @return mixed |
175 | */ |
176 | abstract public function getFailedJob(int $index, bool $unserialize = true): mixed; |
177 | |
178 | /** |
179 | * Check if adapter has failed jobs |
180 | * |
181 | * @return bool |
182 | */ |
183 | abstract public function hasFailedJobs(): bool; |
184 | |
185 | /** |
186 | * Get adapter failed jobs |
187 | * |
188 | * @param bool $unserialize |
189 | * @return array |
190 | */ |
191 | abstract public function getFailedJobs(bool $unserialize = true): array; |
192 | |
193 | /** |
194 | * Clear failed jobs out of the queue |
195 | * |
196 | * @return AbstractAdapter |
197 | */ |
198 | abstract public function clearFailed(): AbstractAdapter; |
199 | |
200 | /** |
201 | * Clear jobs out of queue |
202 | * |
203 | * @return AbstractAdapter |
204 | */ |
205 | abstract public function clear(): AbstractAdapter; |
206 | |
207 | } |