summaryrefslogtreecommitdiff
path: root/src/launcher.php
blob: d1b98925247389a980df18cc40ea588dec3b27dc (plain)
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
<?php

require_once __DIR__.'/init.php';

set_time_limit(0);
$job = null;

register_shutdown_function(function() {
    global $job;
    if ($job !== true)
        exit(1);
});

$job_id = $argv[1] ?? null;

$job_raw = jobs::get($job_id);
if (!$job_raw)
    throw new InvalidArgumentException("job $job_id not found");

$class_name = "jobs\\{$job_raw['name']}";
$job = new $class_name($job_raw);
if ($job->status != Job::STATUS_RUNNING)
    throw new RuntimeException("job status is {$job->status}");

try {
    if ($job->run() !== false)
        $job = true;
} catch (Exception $e) {
    fprintf(STDERR, $e.'');
    exit(1);
}