aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Job/FetchObject.php
blob: 227e05b06d47cebd57ebf7e822f523456a20c5a9 (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
<?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");
        }
    }
}