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
Push — master ( 55c789...0770d4 )
by Damian
10s
created

DoormanRunner::runQueue()   C

Complexity

Conditions 7
Paths 12

Size

Total Lines 37
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 37
rs 6.7272
cc 7
eloc 19
nc 12
nop 1
1
<?php
2
3
namespace Symbiote\QueuedJobs\Tasks\Engines;
4
5
use AsyncPHP\Doorman\Manager\ProcessManager;
6
use SilverStripe\Core\Environment;
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
    /**
18
     * @var string
19
     */
20
    protected $defaultRules = array();
21
22
    /**
23
     * Assign default rules for this task
24
     *
25
     * @param array $rules
26
     */
27
    public function setDefaultRules($rules)
28
    {
29
        $this->defaultRules = $rules;
0 ignored issues
show
Documentation Bug introduced by
It seems like $rules of type array is incompatible with the declared type string of property $defaultRules.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
30
    }
31
32
    /**
33
     * @return array List of rules
34
     */
35
    public function getDefaultRules()
36
    {
37
        return $this->defaultRules;
38
    }
39
40
    /**
41
     * Run tasks on the given queue
42
     *
43
     * @param string $queue
44
     */
45
    public function runQueue($queue)
46
    {
47
48
        // split jobs out into multiple tasks...
49
50
        $manager = new ProcessManager();
51
        $manager->setWorker(BASE_PATH . "/vendor/silverstripe/framework/cli-script.php dev/tasks/ProcessJobQueueChildTask");
52
        $logPath = Environment::getEnv('SS_DOORMAN_LOGPATH');
0 ignored issues
show
Bug introduced by
The method getEnv() does not seem to exist on object<SilverStripe\Core\Environment>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
        if ($logPath) {
54
            $manager->setLogPath($logPath);
55
        }
56
57
        // Assign default rules
58
        $defaultRules = $this->getDefaultRules();
59
        if ($defaultRules) {
60
            foreach ($defaultRules as $rule) {
0 ignored issues
show
Bug introduced by
The expression $defaultRules of type string is not traversable.
Loading history...
61
                $manager->addRule($rule);
62
            }
63
        }
64
65
        $descriptor = $this->getNextJobDescriptorWithoutMutex($queue);
66
67
        while ($manager->tick() || $descriptor) {
68
            $this->logDescriptorStatus($descriptor, $queue);
0 ignored issues
show
Bug introduced by
It seems like $descriptor can also be of type object<SilverStripe\ORM\DataObject>; however, Symbiote\QueuedJobs\Task...::logDescriptorStatus() does only seem to accept boolean|null|object<Symb...ts\QueuedJobDescriptor>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
69
70
            if ($descriptor instanceof QueuedJobDescriptor) {
71
                $descriptor->JobStatus = QueuedJob::STATUS_INIT;
72
                $descriptor->write();
73
74
                $manager->addTask(new DoormanQueuedJobTask($descriptor));
75
            }
76
77
            sleep(1);
78
79
            $descriptor = $this->getNextJobDescriptorWithoutMutex($queue);
80
        }
81
    }
82
83
    /**
84
     * @param string $queue
85
     * @return null|QueuedJobDescriptor
86
     */
87
    protected function getNextJobDescriptorWithoutMutex($queue)
88
    {
89
        $list = QueuedJobDescriptor::get()
90
            ->filter('JobType', $queue)
91
            ->sort('ID', 'ASC');
92
93
        $descriptor = $list
94
            ->filter('JobStatus', QueuedJob::STATUS_WAIT)
95
            ->first();
96
97
        if ($descriptor) {
98
            return $descriptor;
99
        }
100
101
        return $list
102
            ->filter('JobStatus', QueuedJob::STATUS_NEW)
103
            ->where(sprintf(
104
                '"StartAfter" < \'%s\' OR "StartAfter" IS NULL',
105
                DBDatetime::now()->getValue()
106
            ))
107
            ->first();
108
    }
109
}
110