diff options
Diffstat (limited to 'Digitigrade/Job/PeriodicFetchRemoteFeed.php')
| -rw-r--r-- | Digitigrade/Job/PeriodicFetchRemoteFeed.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Digitigrade/Job/PeriodicFetchRemoteFeed.php b/Digitigrade/Job/PeriodicFetchRemoteFeed.php new file mode 100644 index 0000000..e84757f --- /dev/null +++ b/Digitigrade/Job/PeriodicFetchRemoteFeed.php @@ -0,0 +1,37 @@ +<?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() { + JobQueue::getInstance()->submitDelayedUntil( + $this, + (new \DateTimeImmutable)->add(new \DateInterval(GlobalSettings::getInstance()->get('instance.feedUpdateInterval') ?? 'PT1H')) + ); + } +}
\ No newline at end of file |
