Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2declare(strict_types=1);
3/**
4 * Pop PHP Framework (https://www.popphp.org/)
5 *
6 * @link       https://github.com/popphp/popphp-framework
7 * @author     Nick Sagona, III <nick@popphp.org>
8 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Queue\Process;
16
17use Pop\Application;
18
19/**
20 * Job interface
21 *
22 * @category   Pop
23 * @package    Pop\Queue
24 * @author     Nick Sagona, III <nick@popphp.org>
25 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
26 * @license    https://www.popphp.org/license     New BSD License
27 * @version    3.0.0
28 */
29interface JobInterface
30{
31
32    /**
33     * Generate job ID
34     *
35     * @return string
36     */
37    public function generateJobId(): string;
38
39    /**
40     * Set job ID
41     *
42     * @param  string $id
43     * @return JobInterface
44     */
45    public function setJobId(string $id): JobInterface;
46
47    /**
48     * Get job ID
49     *
50     * @return ?string
51     */
52    public function getJobId(): ?string;
53
54    /**
55     * Has job ID
56     *
57     * @return bool
58     */
59    public function hasJobId(): bool;
60
61    /**
62     * Set job description
63     *
64     * @param  string $description
65     * @return JobInterface
66     */
67    public function setJobDescription(string $description): JobInterface;
68
69    /**
70     * Get job description
71     *
72     * @return ?string
73     */
74    public function getJobDescription(): ?string;
75
76    /**
77     * Has job description
78     *
79     * @return bool
80     */
81    public function hasJobDescription(): bool;
82
83    /**
84     * Get job results
85     *
86     * @return mixed
87     */
88    public function getResults(): mixed;
89
90    /**
91     * Has job results
92     *
93     * @return bool
94     */
95    public function hasResults(): bool;
96
97    /**
98     * Set job callable
99     *
100     * @param  mixed $callable
101     * @param  mixed $params
102     * @return JobInterface
103     */
104    public function setCallable(mixed $callable, mixed $params = null): JobInterface;
105
106    /**
107     * Set job application command
108     *
109     * @param  string $command
110     * @return JobInterface
111     */
112    public function setCommand(string|array $command): JobInterface;
113
114    /**
115     * Set job CLI executable command
116     *
117     * @param  string|array $command
118     * @return JobInterface
119     */
120    public function setExec(string|array $command): JobInterface;
121
122    /**
123     * Get job callable
124     *
125     * @return mixed
126     */
127    public function getCallable(): mixed;
128
129    /**
130     * Get job application command
131     *
132     * @return ?string
133     */
134    public function getCommand(): string|array|null;
135
136    /**
137     * Get job CLI executable command
138     *
139     * @return string|array|null
140     */
141    public function getExec(): string|array|null;
142
143    /**
144     * Has job callable
145     *
146     * @return bool
147     */
148    public function hasCallable(): bool;
149
150    /**
151     * Has job application command
152     *
153     * @return bool
154     */
155    public function hasCommand(): bool;
156
157    /**
158     * Has job CLI executable command
159     *
160     * @return bool
161     */
162    public function hasExec(): bool;
163
164    /**
165     * Set max attempts
166     *
167     * @param  int $maxAttempts
168     * @return JobInterface
169     */
170    public function setMaxAttempts(int $maxAttempts): JobInterface;
171
172    /**
173     * Get max attempts
174     *
175     * @return int
176     */
177    public function getMaxAttempts(): int;
178
179    /**
180     * Has max attempts
181     *
182     * @return bool
183     */
184    public function hasMaxAttempts(): bool;
185
186    /**
187     * Is job set for only one max attempt
188     *
189     * @return bool
190     */
191    public function isAttemptOnce(): bool;
192
193    /**
194     * Get actual attempts
195     *
196     * @return int
197     */
198    public function getAttempts(): int;
199
200    /**
201     * Has actual attempts
202     *
203     * @return bool
204     */
205    public function hasAttempts(): bool;
206
207    /**
208     * Set the run until property
209     *
210     * @param  int|string $runUntil
211     * @return JobInterface
212     */
213    public function runUntil(int|string $runUntil): JobInterface;
214
215    /**
216     * Has run until
217     *
218     * @return bool
219     */
220    public function hasRunUntil(): bool;
221
222    /**
223     * Get run until value
224     *
225     * @return int|string|null
226     */
227    public function getRunUntil(): int|string|null;
228
229    /**
230     * Determine if the job has expired
231     *
232     * @return bool
233     */
234    public function isExpired(): bool;
235
236    /**
237     * Determine if the job has exceeded max attempts
238     *
239     * @return bool
240     */
241    public function hasExceededMaxAttempts(): bool;
242
243    /**
244     * Determine if the job is still valid
245     *
246     * @return bool
247     */
248    public function isValid(): bool;
249
250    /**
251     * Has job run yet
252     *
253     * @return bool
254     */
255    public function hasNotRun(): bool;
256
257    /**
258     * Start job
259     *
260     * @return JobInterface
261     */
262    public function start(): JobInterface;
263
264    /**
265     * Get started timestamp
266     *
267     * @return ?int
268     */
269    public function getStarted(): ?int;
270
271    /**
272     * Has job started
273     *
274     * @return bool
275     */
276    public function hasStarted(): bool;
277
278    /**
279     * Is job running and has not completed or failed yet
280     *
281     * @return bool
282     */
283    public function isRunning(): bool;
284
285    /**
286     * Complete job
287     *
288     * @return JobInterface
289     */
290    public function complete(): JobInterface;
291
292    /**
293     * Get completed timestamp
294     *
295     * @return ?int
296     */
297    public function getCompleted(): ?int;
298
299    /**
300     * Is job complete
301     *
302     * @return bool
303     */
304    public function isComplete(): bool;
305
306    /**
307     * Set job as failed
308     *
309     * @param  ?string $message
310     * @return AbstractJob
311     */
312    function failed(?string $message = null): JobInterface;
313
314    /**
315     * Has job failed
316     *
317     * @return bool
318     */
319    public function hasFailed(): bool;
320
321    /**
322     * Add failed message
323     *
324     * @param  string $message
325     * @return JobInterface
326     */
327    public function addFailedMessage(string $message): JobInterface;
328
329    /**
330     * Has failed messages
331     *
332     * @return bool
333     */
334    public function hasFailedMessages(): bool;
335
336    /**
337     * Get failed messages
338     *
339     * @return array
340     */
341    public function getFailedMessages(): array;
342
343    /**
344     * Get failed timestamp
345     *
346     * @return ?int
347     */
348    public function getFailed(): ?int;
349    
350    /**
351     * Run job
352     *
353     * @param  ?Application $application
354     * @return mixed
355     */
356    public function run(?Application $application = null): mixed;
357
358}