aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Job.php
diff options
context:
space:
mode:
authorwinter2024-12-19 18:01:29 +0000
committerwinter2024-12-19 18:01:29 +0000
commit1e070a7a0097c74f8ac30678d39267f19c76f9f6 (patch)
tree669ba608d8182971752f6bc2ae2ade0b3ff627cf /Digitigrade/Job.php
parent6f767c4562df4a686720ef96396cea0b2f0c6334 (diff)
process pushes in job + fix token expiry job
Diffstat (limited to 'Digitigrade/Job.php')
-rw-r--r--Digitigrade/Job.php21
1 files changed, 18 insertions, 3 deletions
diff --git a/Digitigrade/Job.php b/Digitigrade/Job.php
index 146e4b2..d460b7e 100644
--- a/Digitigrade/Job.php
+++ b/Digitigrade/Job.php
@@ -2,15 +2,28 @@
namespace Digitigrade;
abstract class Job implements \JsonSerializable {
+ private static \JsonMapper $mapper;
+
public int $remainingTries;
public int $doneTries = 0;
+ public static function __initStatic() {
+ self::$mapper = new \JsonMapper();
+ // to parse DateTime(Immutable)s properly
+ self::$mapper->bStrictObjectTypeChecking = false;
+ self::$mapper->classMap[\DateTimeInterface::class] = \DateTimeImmutable::class;
+ }
+
public function jsonSerialize(): array {
$array = ['jobSubtype' => 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;
+ if ($value instanceof \DateTimeInterface) {
+ $array[$prop->getName()] = $value->format('c');
+ } else {
+ $array[$prop->getName()] = $value;
+ }
}
return $array;
}
@@ -20,7 +33,7 @@ abstract class Job implements \JsonSerializable {
if (!property_exists($obj, 'jobSubtype')) {
return null;
}
- return (new \JsonMapper())->map($obj, $obj->jobSubtype);
+ return self::$mapper->map($obj, $obj->jobSubtype);
}
/**
@@ -36,4 +49,6 @@ abstract class Job implements \JsonSerializable {
public function submit() {
JobQueue::getInstance()->submitNormal($this);
}
-} \ No newline at end of file
+}
+
+Job::__initStatic(); \ No newline at end of file