diff options
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 |