diff options
| author | winter | 2024-12-14 16:26:30 +0000 |
|---|---|---|
| committer | winter | 2024-12-14 16:26:30 +0000 |
| commit | 4dc9d1a481417bb78606996fa75c791bb646f44f (patch) | |
| tree | 1e5c1beff234999a0a0eb9819515644ec73d965d /Digitigrade/Job | |
| parent | 86cf52e8d2701e13bd9fd4c847b35eba7506c473 (diff) | |
job queue and workers and loggers!
Diffstat (limited to 'Digitigrade/Job')
| -rw-r--r-- | Digitigrade/Job/FetchObject.php | 25 | ||||
| -rw-r--r-- | Digitigrade/Job/UpdateInstanceInfo.php | 22 |
2 files changed, 47 insertions, 0 deletions
diff --git a/Digitigrade/Job/FetchObject.php b/Digitigrade/Job/FetchObject.php new file mode 100644 index 0000000..227e05b --- /dev/null +++ b/Digitigrade/Job/FetchObject.php @@ -0,0 +1,25 @@ +<?php +namespace Digitigrade\Job; + +use Digitigrade\Job; +use Digitigrade\Logger; +use Digitigrade\Model\FetchableModel; + +class FetchObject extends Job { + public string $uri; + public string $type; + + public function __construct(string $type, string $uri) { + $this->type = $type; + $this->uri = $uri; + $this->remainingTries = 8; + } + + public function run() { + assert(is_subclass_of($this->type, FetchableModel::class)); + Logger::getInstance()->info("fetching $this->type at $this->uri"); + if ($this->type::findByUri($this->uri, forceRefetch: true) == null) { + throw new \RuntimeException("remote object doesn't seem to exist"); + } + } +}
\ No newline at end of file diff --git a/Digitigrade/Job/UpdateInstanceInfo.php b/Digitigrade/Job/UpdateInstanceInfo.php new file mode 100644 index 0000000..85c11f0 --- /dev/null +++ b/Digitigrade/Job/UpdateInstanceInfo.php @@ -0,0 +1,22 @@ +<?php +namespace Digitigrade\Job; + +use Digitigrade\Job; +use Digitigrade\Logger; +use Digitigrade\Model\Instance; + +class UpdateInstanceInfo extends Job { + public string $domain; + + public function __construct(string $domain) { + $this->domain = $domain; + $this->remainingTries = 3; + } + + public function run() { + Logger::getInstance()->info("updating info for instance $this->domain"); + if (Instance::findByDomain($this->domain, forceRefetch: true) == null) { + throw new \RuntimeException("remote object doesn't seem to exist"); + } + } +}
\ No newline at end of file |
