blob: c64446dd50d858af73e03dd5bd4e31e7e50e2071 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
<?php
namespace Digitigrade\Job;
use Digitigrade\GlobalSettings;
use Digitigrade\Job;
use Digitigrade\JobQueue;
use Digitigrade\Logger;
use Digitigrade\Model\Actor;
class PeriodicFetchRemoteFeed extends Job {
public int $actorId;
public function __construct(Actor $targetActor) {
$this->actorId = $targetActor->id;
$this->remainingTries = 8;
}
public function run() {
$actor = Actor::find($this->actorId);
$logger = Logger::getInstance();
// only bother if someone local still follows the actor
if (count(array_filter($actor->findFollowers(), fn(Actor $a) => $a->isLocal)) > 0) {
$logger->info('Fetching feed for simple remote actor ' . $actor->getFullHandle());
$actor->backfill(GlobalSettings::getInstance()->get('instance.feedUpdateLimit') ?? 50);
$this->submit();
} else {
$logger->info('No longer fetching feed for ' . $actor->getFullHandle() . ' as nobody follows them anymore');
}
}
public function submit(bool $now = false) {
if ($now) {
JobQueue::getInstance()->submitUrgent($this);
} else {
JobQueue::getInstance()->submitDelayedUntil(
$this,
(new \DateTimeImmutable)->add(new \DateInterval(GlobalSettings::getInstance()->get('instance.feedUpdateInterval') ?? 'PT1H'))
);
}
}
}
|