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.

ProcessJobQueueTask::getDescription()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Symbiote\QueuedJobs\Tasks;
4
5
use SilverStripe\Control\HTTPRequest;
6
use SilverStripe\Dev\BuildTask;
7
use Symbiote\QueuedJobs\Services\QueuedJob;
8
use Symbiote\QueuedJobs\Services\QueuedJobService;
9
10
/**
11
 * Task used to process the job queue
12
 *
13
 * @author Marcus Nyeholt <[email protected]>
14
 * @license BSD http://silverstripe.org/bsd-license/
15
 */
16
class ProcessJobQueueTask extends BuildTask
17
{
18
    /**
19
     * {@inheritDoc}
20
     * @var string
21
     */
22
    private static $segment = 'ProcessJobQueueTask';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
23
24
    /**
25
     * @return string
26
     */
27
    public function getDescription()
28
    {
29
        return _t(
30
            __CLASS__ . '.Description',
31
            'Used via a cron job to execute queued jobs that need to be run.'
32
        );
33
    }
34
35
    /**
36
     * @param HTTPRequest $request
37
     */
38
    public function run($request)
39
    {
40
        if (QueuedJobService::singleton()->isMaintenanceLockActive()) {
41
            return;
42
        }
43
44
        $service = $this->getService();
45
46
        if ($request->getVar('list')) {
47
            // List helper
48
            $service->queueRunner->listJobs();
49
            return;
50
        }
51
52
        // Check if there is a job to run
53
        if (($job = $request->getVar('job')) && strpos($job, '-')) {
54
            // Run from a isngle job
55
            $parts = explode('-', $job);
56
            $id = $parts[1];
57
            $service->runJob($id);
58
            return;
59
        }
60
61
        // Run the queue
62
        $queue = $this->getQueue($request);
63
        $service->runQueue($queue);
64
    }
65
66
    /**
67
     * Resolves the queue name to one of a few aliases.
68
     *
69
     * @todo Solve the "Queued"/"queued" mystery!
70
     *
71
     * @param HTTPRequest $request
72
     * @return string
73
     */
74
    protected function getQueue($request)
75
    {
76
        $queue = $request->getVar('queue');
77
78
        if (!$queue) {
79
            $queue = 'Queued';
80
        }
81
82
        switch (strtolower($queue)) {
83
            case 'immediate':
84
                $queue = QueuedJob::IMMEDIATE;
85
                break;
86
            case 'queued':
87
                $queue = QueuedJob::QUEUED;
88
                break;
89
            case 'large':
90
                $queue = QueuedJob::LARGE;
91
                break;
92
            default:
93
                break;
94
        }
95
96
        return $queue;
97
    }
98
99
    /**
100
     * Returns an instance of the QueuedJobService.
101
     *
102
     * @return QueuedJobService
103
     */
104
    public function getService()
105
    {
106
        return QueuedJobService::singleton();
107
    }
108
}
109