aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Job/ProcessIncomingSimplePush.php
diff options
context:
space:
mode:
authorwinter2025-03-31 21:29:22 +0100
committerwinter2025-03-31 21:29:22 +0100
commita9f0003e809d46093e783d2079be7a952b5f5e0d (patch)
tree154cb0ad413756a265baebeee45a868d3ed79879 /Digitigrade/Job/ProcessIncomingSimplePush.php
parent8c3f045ed44bcb27189a605a4b86e5db22fee4d6 (diff)
implement backfilling for newly discovered actors
Diffstat (limited to 'Digitigrade/Job/ProcessIncomingSimplePush.php')
-rw-r--r--Digitigrade/Job/ProcessIncomingSimplePush.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/Digitigrade/Job/ProcessIncomingSimplePush.php b/Digitigrade/Job/ProcessIncomingSimplePush.php
new file mode 100644
index 0000000..a48a70b
--- /dev/null
+++ b/Digitigrade/Job/ProcessIncomingSimplePush.php
@@ -0,0 +1,44 @@
+<?php
+namespace Digitigrade\Job;
+
+use Digitigrade\Job;
+use Digitigrade\JobQueue;
+use Digitigrade\Logger;
+
+class ProcessIncomingSimplePush extends Job {
+ public string $uri;
+
+ public function __construct(string $uri) {
+ $this->uri = $uri;
+ $this->remainingTries = 3;
+ }
+
+ public function run() {
+ $log = Logger::getInstance();
+
+ $log->info("processing simple push for $this->uri");
+
+ $result = send_request_authenticated($this->uri);
+ if (!str_contains($result->headers[0], '200')) {
+ throw new \RuntimeException("unable to fetch given simple push uri: $this->uri");
+ }
+ $obj = json_decode($result->body);
+
+ if ($obj === null) {
+ throw new \RuntimeException("fetched content doesn't look like valid json");
+ }
+ if (!isset($obj->type, $obj->self)) {
+ throw new \RuntimeException('the object needs to have `type` and `self` properties');
+ }
+ if ($obj->self != $this->uri) {
+ throw new \RuntimeException("fetched object has a different uri from the one provided ($obj->self != $this->uri)");
+ }
+
+ $log->info('fetch successful, pushed object will be dealt with soon');
+ (new ProcessIncomingPush($obj))->submit();
+ }
+
+ public function submitDelayed(int $delaySecs) {
+ JobQueue::getInstance()->submitDelayed($this, $delaySecs);
+ }
+} \ No newline at end of file