public function checkDefaultJobs($queue = null)
    {
        $queue = $queue ?: QueuedJob::QUEUED;
        if (count($this->defaultJobs)) {
            $activeJobs = QueuedJobDescriptor::get()->filter(
                'JobStatus',
                [
                    QueuedJob::STATUS_NEW,
                    QueuedJob::STATUS_INIT,
                    QueuedJob::STATUS_RUN,
                    QueuedJob::STATUS_WAIT,
                    QueuedJob::STATUS_PAUSED,
                ]
            );
            foreach ($this->defaultJobs as $title => $jobConfig) {
                if (!isset($jobConfig['filter']) || !isset($jobConfig['type'])) {
                    $this->getLogger()->error(
                        "Default Job config: $title incorrectly set up. Please check the readme for examples",
                        [
                            'file' => __FILE__,
                            'line' => __LINE__,
                        ]
                    );
                    continue;
                }
                $job = $activeJobs->filter(array_merge(
                    ['Implementation' => $jobConfig['type']],
                    $jobConfig['filter']
                ));
                if (!$job->count()) {
                    $this->getLogger()->error(
                        "Default Job config: $title was missing from Queue",
                        [
                            'file' => __FILE__,
                            'line' => __LINE__,
                        ]
                    );
                    Email::create()
                        ->setTo(
                            isset($jobConfig['email'])
                                ? $jobConfig['email']
                                : Config::inst()->get(Email::class, 'queued_job_admin_email')
                        )
                        ->setFrom(Config::inst()->get(Email::class, 'admin_email'))
                        ->setSubject('Default Job "' . $title . '" missing')
                        ->setData($jobConfig)
                        ->addData('Title', $title)
                        ->addData('Site', Director::absoluteBaseURL())
                        ->setHTMLTemplate('QueuedJobsDefaultJob')
                        ->send();
                    if (isset($jobConfig['recreate']) && $jobConfig['recreate']) {
                        if (!array_key_exists('construct', $jobConfig)
                            || !isset($jobConfig['startDateFormat'])
                            || !isset($jobConfig['startTimeString'])
                        ) {
                            $this->getLogger()->error(
                                "Default Job config: $title incorrectly set up. Please check the readme for examples",
                                [
                                    'file' => __FILE__,
                                    'line' => __LINE__,
                                ]
                            );
                            continue;
                        }
                        QueuedJobService::singleton()->queueJob(
                            Injector::inst()->createWithArgs($jobConfig['type'], $jobConfig['construct']),
                            date($jobConfig['startDateFormat'], strtotime($jobConfig['startTimeString']))
                        );
                        $this->getLogger()->info(
                            "Default Job config: $title has been re-added to the Queue",
                            [
                                'file' => __FILE__,
                                'line' => __LINE__,
                            ]
                        );
                    }
                }
            }
        }
    }
public function checkDefaultJobs($queue = null)
    {
        $queue = $queue ?: QueuedJob::QUEUED;
        if (count($this->defaultJobs)) {
            $activeJobs = QueuedJobDescriptor::get()->filter(
                'JobStatus',
                [
                    QueuedJob::STATUS_NEW,
                    QueuedJob::STATUS_INIT,
                    QueuedJob::STATUS_RUN,
                    QueuedJob::STATUS_WAIT,
                    QueuedJob::STATUS_PAUSED,
                ]
            );
            foreach ($this->defaultJobs as $title => $jobConfig) {
                if (!isset($jobConfig['filter']) || !isset($jobConfig['type'])) {
                    $this->getLogger()->error(
                        "Default Job config: $title incorrectly set up. Please check the readme for examples",
                        [
                            'file' => __FILE__,
                            'line' => __LINE__,
                        ]
                    );
                    continue;
                }
                $job = $activeJobs->filter(array_merge(
                    ['Implementation' => $jobConfig['type']],
                    $jobConfig['filter']
                ));
                if (!$job->count()) {
                    $this->getLogger()->error(
                        "Default Job config: $title was missing from Queue",
                        [
                            'file' => __FILE__,
                            'line' => __LINE__,
                        ]
                    );
                    Email::create()
                        ->setTo(
                            isset($jobConfig['email'])
                                ? $jobConfig['email']
                                : Config::inst()->get(Email::class, 'queued_job_admin_email')
                        )
                        ->setFrom(Config::inst()->get(Email::class, 'admin_email'))
                        ->setSubject('Default Job "' . $title . '" missing')
                        ->setData($jobConfig)
                        ->addData('Title', $title)
                        ->addData('Site', Director::absoluteBaseURL())
                        ->setHTMLTemplate('QueuedJobsDefaultJob')
                        ->send();
                    if (isset($jobConfig['recreate']) && $jobConfig['recreate']) {
                        if (!array_key_exists('construct', $jobConfig)
                            || !isset($jobConfig['startDateFormat'])
                            || !isset($jobConfig['startTimeString'])
                        ) {
                            $this->getLogger()->error(
                                "Default Job config: $title incorrectly set up. Please check the readme for examples",
                                [
                                    'file' => __FILE__,
                                    'line' => __LINE__,
                                ]
                            );
                            continue;
                        }
                        QueuedJobService::singleton()->queueJob(
                            Injector::inst()->createWithArgs($jobConfig['type'], $jobConfig['construct']),
                            date($jobConfig['startDateFormat'], strtotime($jobConfig['startTimeString']))
                        );
                        $this->getLogger()->info(
                            "Default Job config: $title has been re-added to the Queue",
                            [
                                'file' => __FILE__,
                                'line' => __LINE__,
                            ]
                        );
                    }
                }
            }
        }
    }
public function checkDefaultJobs ( $ queue = null ) { $ queue = $ queue ? : QueuedJob :: QUEUED ; if ( count ( $ this -> defaultJobs ) ) { $ activeJobs = QueuedJobDescriptor :: get ( ) -> filter ( 'JobStatus' , [ QueuedJob :: STATUS_NEW , QueuedJob :: STATUS_INIT , QueuedJob :: STATUS_RUN , QueuedJob :: STATUS_WAIT , QueuedJob :: STATUS_PAUSED , ] ) ; foreach ( $ this -> defaultJobs as $ title => $ jobConfig ) { if ( ! isset ( $ jobConfig [ 'filter' ] ) || ! isset ( $ jobConfig [ 'type' ] ) ) { $ this -> getLogger ( ) -> error ( "Default Job config: $title incorrectly set up. Please check the readme for examples" , [ 'file' => __FILE__ , 'line' => __LINE__ , ] ) ; continue ; } $ job = $ activeJobs -> filter ( array_merge ( [ 'Implementation' => $ jobConfig [ 'type' ] ] , $ jobConfig [ 'filter' ] ) ) ; if ( ! $ job -> count ( ) ) { $ this -> getLogger ( ) -> error ( "Default Job config: $title was missing from Queue" , [ 'file' => __FILE__ , 'line' => __LINE__ , ] ) ; Email :: create ( ) -> setTo ( isset ( $ jobConfig [ 'email' ] ) ? $ jobConfig [ 'email' ] : Config :: inst ( ) -> get ( Email :: class , 'queued_job_admin_email' ) ) -> setFrom ( Config :: inst ( ) -> get ( Email :: class , 'admin_email' ) ) -> setSubject ( 'Default Job "' . $ title . '" missing' ) -> setData ( $ jobConfig ) -> addData ( 'Title' , $ title ) -> addData ( 'Site' , Director :: absoluteBaseURL ( ) ) -> setHTMLTemplate ( 'QueuedJobsDefaultJob' ) -> send ( ) ; if ( isset ( $ jobConfig [ 'recreate' ] ) && $ jobConfig [ 'recreate' ] ) { if ( ! array_key_exists ( 'construct' , $ jobConfig ) || ! isset ( $ jobConfig [ 'startDateFormat' ] ) || ! isset ( $ jobConfig [ 'startTimeString' ] ) ) { $ this -> getLogger ( ) -> error ( "Default Job config: $title incorrectly set up. Please check the readme for examples" , [ 'file' => __FILE__ , 'line' => __LINE__ , ] ) ; continue ; } QueuedJobService :: singleton ( ) -> queueJob ( Injector :: inst ( ) -> createWithArgs ( $ jobConfig [ 'type' ] , $ jobConfig [ 'construct' ] ) , date ( $ jobConfig [ 'startDateFormat' ] , strtotime ( $ jobConfig [ 'startTimeString' ] ) ) ) ; $ this -> getLogger ( ) -> info ( "Default Job config: $title has been re-added to the Queue" , [ 'file' => __FILE__ , 'line' => __LINE__ , ] ) ; } } } } }
Checks through ll the scheduled jobs that are expected to exist
Checks through ll the scheduled jobs that are expected to exist