GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#178)
by Robbie
01:47
created

DoormanRunner::setDefaultRules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Symbiote\QueuedJobs\Tasks\Engines;
4
5
use AsyncPHP\Doorman\Manager\ProcessManager;
6
use SilverStripe\Core\Config\Configurable;
7
use SilverStripe\ORM\FieldType\DBDatetime;
8
use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor;
9
use Symbiote\QueuedJobs\Jobs\DoormanQueuedJobTask;
10
use Symbiote\QueuedJobs\Services\QueuedJob;
11
12
/**
13
 * Runs all jobs through the doorman engine
14
 */
15
class DoormanRunner extends BaseRunner implements TaskRunnerEngine
16
{
17
    use Configurable;
18
19
    /**
20
     * Optional: configure a log path for the runner
21
     *
22
     * @config
23
     * @var string|null
24
     */
25
    private static $log_path = null;
26
27
    /**
28
     * @var string
29
     */
30
    protected $defaultRules = array();
31
32
    /**
33
     * Assign default rules for this task
34
     *
35
     * @param array $rules
36
     */
37
    public function setDefaultRules($rules)
38
    {
39
        $this->defaultRules = $rules;
40
    }
41
42
    /**
43
     * @return array List of rules
44
     */
45
    public function getDefaultRules()
46
    {
47
        return $this->defaultRules;
48
    }
49
50
    /**
51
     * Run tasks on the given queue
52
     *
53
     * @param string $queue
54
     */
55
    public function runQueue($queue)
56
    {
57
58
        // split jobs out into multiple tasks...
59
60
        $manager = new ProcessManager();
61
        $manager->setWorker(BASE_PATH . "/vendor/silverstripe/framework/cli-script.php dev/tasks/ProcessJobQueueChildTask");
62
        $logPath = $this->config()->get('log_path')
63
        if ($logPath) {
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_IF
Loading history...
64
            $manager->setLogPath($logPath);
65
        }
66
67
        // Assign default rules
68
        $defaultRules = $this->getDefaultRules();
69
        if ($defaultRules) {
70
            foreach ($defaultRules as $rule) {
71
                $manager->addRule($rule);
72
            }
73
        }
74
75
        $descriptor = $this->getNextJobDescriptorWithoutMutex($queue);
76
77
        while ($manager->tick() || $descriptor) {
78
            $this->logDescriptorStatus($descriptor, $queue);
79
80
            if ($descriptor instanceof QueuedJobDescriptor) {
81
                $descriptor->JobStatus = QueuedJob::STATUS_INIT;
82
                $descriptor->write();
83
84
                $manager->addTask(new DoormanQueuedJobTask($descriptor));
85
            }
86
87
            sleep(1);
88
89
            $descriptor = $this->getNextJobDescriptorWithoutMutex($queue);
90
        }
91
    }
92
93
    /**
94
     * @param string $queue
95
     * @return null|QueuedJobDescriptor
96
     */
97
    protected function getNextJobDescriptorWithoutMutex($queue)
98
    {
99
        $list = QueuedJobDescriptor::get()
100
            ->filter('JobType', $queue)
101
            ->sort('ID', 'ASC');
102
103
        $descriptor = $list
104
            ->filter('JobStatus', QueuedJob::STATUS_WAIT)
105
            ->first();
106
107
        if ($descriptor) {
108
            return $descriptor;
109
        }
110
111
        return $list
112
            ->filter('JobStatus', QueuedJob::STATUS_NEW)
113
            ->where(sprintf(
114
                '"StartAfter" < \'%s\' OR "StartAfter" IS NULL',
115
                DBDatetime::now()->getValue()
116
            ))
117
            ->first();
118
    }
119
}
120