/
Cron.php
411 lines (358 loc) · 8.42 KB
/
Cron.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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
<?php
declare(strict_types=1);
/**
* This file is part of Narrowspark Framework.
*
* (c) Daniel Bannert <d.bannert@anolilab.de>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Viserio\Contract\Cron;
use Closure;
interface Cron
{
/**
* Get the command name.
*
* @return string
*/
public function getCommand(): string;
/**
* Set which user the command should run as.
*
* @param string $user
*
* @return static
*/
public function setUser(string $user): self;
/**
* Get which user runs the command.
*
* @return string
*/
public function getUser(): string;
/**
* Limit the environments the command should run in.
*
* @param array|mixed $environments
*
* @return static
*/
public function setEnvironments($environments): self;
/**
* Determine if the cron runs in the given environment.
*
* @param string $environment
*
* @return bool
*/
public function runsInEnvironment(string $environment): bool;
/**
* Run the given cron job.
*
* @return mixed
*/
public function run();
/**
* State that the command should run in background.
*
* @return static
*/
public function runInBackground(): self;
/**
* Build the command string.
*
* @return string
*/
public function buildCommand(): string;
/**
* Do not allow the cron job to overlap each other.
*
* @return static
*/
public function withoutOverlapping(): self;
/**
* Append the output of the command to a given location.
*
* @param string $location
*
* @return static
*/
public function appendOutputTo(string $location): self;
/**
* Send the output of the command to a given location.
*
* @param string $location
*
* @return static
*/
public function sendOutputTo(string $location): self;
/**
* Determine if the given cron job should run based on the Cron expression.
*
* @param string $environment
* @param bool $isMaintenance
*
* @return bool
*/
public function isDue(string $environment, bool $isMaintenance = false): bool;
/**
* Get the cron expression for the cron job.
*
* @return string
*/
public function getExpression(): string;
/**
* The Cron expression representing the cron's frequency.
*
* @param string $expression
*
* @return static
*/
public function cron(string $expression);
/**
* Schedule the cron job to run hourly.
*
* @return static
*/
public function hourly(): self;
/**
* Schedule the cron job to run daily.
*
* @return static
*/
public function daily(): self;
/**
* Schedule the cron job to run monthly.
*
* @return static
*/
public function monthly(): self;
/**
* Schedule the cron job to run yearly.
*
* @return static
*/
public function yearly(): self;
/**
* Schedule the cron job to run quarterly.
*
* @return static
*/
public function quarterly(): self;
/**
* Schedule the cron job to run every minute.
*
* @return static
*/
public function everyMinute(): self;
/**
* Schedule the cron job to run every five minutes.
*
* @return static
*/
public function everyFiveMinutes(): self;
/**
* Schedule the cron job to run every ten minutes.
*
* @return static
*/
public function everyTenMinutes(): self;
/**
* Schedule the event to run every fifteen minutes.
*
* @return static
*/
public function everyFifteenMinutes(): self;
/**
* Schedule the cron job to run every thirty minutes.
*
* @return static
*/
public function everyThirtyMinutes(): self;
/**
* Set the days of the week the command should run on.
*
* @param array|int|string $days
*
* @return static
*/
public function days($days): self;
/**
* Schedule the cron job to run monthly on a given day and time.
*
* @param int $day
* @param string $time
*
* @return static
*/
public function monthlyOn(int $day = 1, string $time = '0:0'): self;
/**
* Schedule the cron job to run daily at a given time (10:00, 19:30, etc).
*
* @param string $time
*
* @return static
*/
public function dailyAt(string $time): self;
/**
* Schedule the cron job to run twice daily.
*
* @param int $first
* @param int $second
*
* @return static
*/
public function twiceDaily(int $first = 1, int $second = 13): self;
/**
* Schedule the cron to run twice monthly.
*
* @param int $first
* @param int $second
*
* @return static
*/
public function twiceMonthly(int $first = 1, int $second = 16): self;
/**
* Schedule the cron job to run only on weekdays.
*
* @return static
*/
public function weekdays(): self;
/**
* Schedule the cron job to run only on Mondays.
*
* @return static
*/
public function mondays(): self;
/**
* Schedule the cron job to run only on Tuesdays.
*
* @return static
*/
public function tuesdays(): self;
/**
* Schedule the cron job to run only on Wednesdays.
*
* @return static
*/
public function wednesdays(): self;
/**
* Schedule the cron job to run only on Thursdays.
*
* @return static
*/
public function thursdays(): self;
/**
* Schedule the cron job to run only on Fridays.
*
* @return static
*/
public function fridays(): self;
/**
* Schedule the cron job to run only on Saturdays.
*
* @return static
*/
public function saturdays(): self;
/**
* Schedule the cron job to run only on Sundays.
*
* @return static
*/
public function sundays(): self;
/**
* Schedule the cron job to run weekly.
*
* @return static
*/
public function weekly(): self;
/**
* Schedule the cron job to run weekly on a given day and time.
*
* @param int $day
* @param string $time
*
* @return static
*/
public function weeklyOn(int $day, string $time = '0:0'): self;
/**
* Schedule the cron job to run between start and end time.
*
* @param string $startTime
* @param string $endTime
*
* @return static
*/
public function between(string $startTime, string $endTime): self;
/**
* Schedule the cron job to not run between start and end time.
*
* @param string $startTime
* @param string $endTime
*
* @return static
*/
public function unlessBetween(string $startTime, string $endTime): self;
/**
* Register a callback to further filter the schedule.
*
* @param Closure $callback
*
* @return static
*/
public function when(Closure $callback): self;
/**
* Register a callback to further filter the schedule.
*
* @param Closure $callback
*
* @return static
*/
public function skip(Closure $callback): self;
/**
* Register a callback to be called before the operation.
*
* @param Closure $callback
*
* @return static
*/
public function before(Closure $callback): self;
/**
* Register a callback to be called after the operation.
*
* @param Closure $callback
*
* @return static
*/
public function after(Closure $callback): self;
/**
* Set the human-friendly description of the cron.
*
* @param string $description
*
* @return static
*/
public function setDescription(string $description): self;
/**
* Get the summary of the cron for display.
*
* @return string
*/
public function getSummaryForDisplay(): string;
/**
* Set the timezone the date should be evaluated on.
*
* @param string $timezone
*
* @return static
*/
public function setTimezone(string $timezone): self;
/**
* Determine if the filters pass for the cron.
*
* @return bool
*/
public function filtersPass(): bool;
}