Completed
Pull Request — master (#176)
by Robbie
08:50 queued 07:19
created

SilverStripeElasticaReindexCron::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 6
Ratio 40 %

Importance

Changes 0
Metric Value
dl 6
loc 15
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 0
1
<?php
2
3
use SilverStripe\Elastica\ReindexTask;
4
5
/**
6
 * These regular updates run as often as is practical.
7
 * They seem to take 2-3 hours at the moment, so we run them 4 times per day.
8
 */
9
class SilverStripeElasticaReindexCron implements CronTask
10
{
11
12
    /**
13
     * Run every 6 hours
14
     *
15
     * @return string
16
     */
17
    public function getSchedule()
18
    {
19
        return "0 */6 * * *";
20
    }
21
22
    /**
23
     * Run the build task SilverStripeElasticaReindexTask
24
     * @return void
25
     */
26
    public function process()
27
    {
28
        $taskClasses = [
29
            [UpdateSilverStripeVersionsTask::class, null],
30
            [UpdateAddonsTask::class, null],
31
            [ReindexTask::class, 'reindex=1'],
32
        ];
33
34 View Code Duplication
        foreach ($taskClasses as $taskInfo) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
            list($taskClass, $taskQuerystring) = $taskInfo;
36
            $job = new RunBuildTaskJob($taskClass, $taskQuerystring);
37
            $jobID = Injector::inst()->get(QueuedJobService::class)->queueJob($job);
38
            echo 'Added ' . $taskClass . ' to job queue (job ID ' . $jobID . ")\n";
39
        }
40
    }
41
}
42