diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2021-05-07 23:39:20 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2021-05-07 23:39:30 +0300 |
commit | 9a98ac50ff50dda2f2eed1ea825352c50c64440e (patch) | |
tree | cc5c7d36eee1ec934f8728e7f9104a9d2d760856 /src/launcher.php |
initial
Diffstat (limited to 'src/launcher.php')
-rw-r--r-- | src/launcher.php | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/launcher.php b/src/launcher.php new file mode 100644 index 0000000..d1b9892 --- /dev/null +++ b/src/launcher.php @@ -0,0 +1,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); +}
\ No newline at end of file |