From 4dc9d1a481417bb78606996fa75c791bb646f44f Mon Sep 17 00:00:00 2001 From: winter Date: Sat, 14 Dec 2024 16:26:30 +0000 Subject: job queue and workers and loggers! --- Digitigrade/Job.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Digitigrade/Job.php (limited to 'Digitigrade/Job.php') diff --git a/Digitigrade/Job.php b/Digitigrade/Job.php new file mode 100644 index 0000000..4fc799a --- /dev/null +++ b/Digitigrade/Job.php @@ -0,0 +1,39 @@ + static::class]; + foreach ((new \ReflectionObject($this))->getProperties() as $prop) { + assert($prop instanceof \ReflectionProperty); // for intellisense + $value = $prop->getValue($this); + $array[$prop->getName()] = is_object($value) ? json_encode($value) : $value; + } + return $array; + } + + public static final function fromJson(string $data): ?self { + $obj = json_decode($data); + if (!property_exists($obj, 'jobSubtype')) { + return null; + } + return (new \JsonMapper())->map($obj, $obj->jobSubtype); + } + + /** + * Runs the job. Returns nothing on success, or throws some error/exception. + * @return void + */ + public abstract function run(); + + /** + * Submits the job to the global job queue with default options. + * @return void + */ + public function submit() { + JobQueue::getInstance()->submitNormal($this); + } +} \ No newline at end of file -- cgit v1.3