-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron.php
39 lines (32 loc) · 1.07 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
<?php
require(__DIR__ . '/vendor/autoload.php');
echo "[CRON] Starting tasks scheduler\n";
function build_cron() {
// Increment redis key every minute
$inc_job = new \Cron\Job\ShellJob();
$inc_job->setCommand('php inc.php');
$inc_job->setSchedule(new \Cron\Schedule\CrontabSchedule('*/2 * * * *'));
$resolver = new \Cron\Resolver\ArrayResolver();
$resolver->addJob($inc_job);
$cron = new \Cron\Cron();
$cron->setExecutor(new \Cron\Executor\Executor());
$cron->setResolver($resolver);
return $cron;
}
// Every 60 seconds, run the scheduler which will execute the tasks
// which have to be started at the given minute.
while(true) {
$cron = build_cron();
echo "[CRON] Running tasks\n";
$report = $cron->run();
while ($cron->isRunning()) { }
echo "[CRON] " . count($report->getReports()) . " tasks have been executed\n";
foreach($report->getReports() as $job_report) {
$output = $job_report->getOutput();
foreach($output as $line) {
echo "[CRON] " . $line;
}
}
sleep(60);
}
?>