-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcron
49 lines (37 loc) · 1014 Bytes
/
cron
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
<?php
declare(strict_types=1);
/**
* cron
*
* usage: php cron <interval> <token>
*/
# cli bootstrap
require_once __DIR__ . "/bootstrap/cli.php";
/** */
# check the interval
$interval = $argv[1] ?? null;
$allowedIntervals = ["every", "hourly", "daily", "weekly", "monthly", "yearly"];
if (!in_array($interval, $allowedIntervals)) {
Gazelle\Text::figlet("bad interval", "red");
return;
}
# check the token
$token = $argv[2] ?? null;
if ($token !== $app->env->private("cronToken")) {
Gazelle\Text::figlet("bad token", "red");
return;
}
# set the process title
$processTitle = "{$interval}GazelleCron";
cli_set_process_title($processTitle);
# ensure only one is running
$currentWorkers = intval(exec("ps ax | grep {$processTitle} | grep -v grep | wc -l"));
if ($currentWorkers > 1) {
Gazelle\Text::figlet("too many workers", "red");
return;
}
/** */
# unlimit
$app->unlimit();
# run the scripts for this interval
$app->recursiveGlob(__DIR__ . "/utilities/crontab/{$interval}");