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 (#290)
by
unknown
01:34
created

Task::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace App\Queue\Cleanup;
4
5
use SilverStripe\Control\HTTPRequest;
6
use SilverStripe\Dev\BuildTask;
7
use SilverStripe\ORM\DB;
8
use SilverStripe\ORM\FieldType\DBDatetime;
9
use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor;
10
use Symbiote\QueuedJobs\Services\QueuedJob;
11
use Symbiote\QueuedJobs\Services\QueuedJobService;
12
13
/**
14
 * Class Task
15
 *
16
 * Delete all expired completed jobs
17
 *
18
 * @package App\Queue\Cleanup
19
 */
20
class Task extends BuildTask
21
{
22
23
    private const EXPIRY_HOURS = 24;
24
    private const EXPIRY_LIMIT = 10000;
25
26
    /**
27
     * @var string
28
     */
29
    private static $segment = 'queued-jobs-cleanup';
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...
30
31
    /**
32
     * @var string
33
     */
34
    protected $description = 'Delete job descriptors that are older than the configured expiry';
35
36
    /**
37
     * @param HTTPRequest $request
38
     */
39
    public function run($request): void // phpcs:ignore SlevomatCodingStandard.TypeHints
40
    {
41
        if (QueuedJobService::singleton()->isMaintenanceLockActive()) {
42
            return;
43
        }
44
45
        $table = QueuedJobDescriptor::config()->get('table_name');
46
47
        // determine expiry
48
        $expired = DBDatetime::now()->modify(sprintf('-%s hours', self::EXPIRY_HOURS))->Rfc2822();
49
50
        // Format query
51
        $query = sprintf(
52
            "DELETE FROM `%s` WHERE `JobStatus` = '%s' AND (`JobFinished` <= '%s' OR `JobFinished` IS NULL) LIMIT %d",
53
            $table,
54
            QueuedJob::STATUS_COMPLETE,
55
            $expired,
56
            self::EXPIRY_LIMIT
57
        );
58
59
        DB::query($query);
60
61
        echo sprintf('%d job descriptors deleted.', (int) DB::affected_rows());
62
    }
63
}
64