diff --git a/README.md b/README.md index a887332b..69a19932 100644 --- a/README.md +++ b/README.md @@ -172,30 +172,31 @@ Default jobs are defined in yml config the sample below covers the options and e ``` Injector: QueuedJobService: - defaultJobs: - # This key is used as the title for error logs and alert emails - ArbitraryName: - # The job type should be the class name of a job REQUIRED - type: 'ScheduledExternalImportJob' - # This plus the job type is used to create the SQL query REQUIRED - filter: - # 1 or more Fieldname: 'value' sets that will be queried on REQUIRED - # These can be valid ORM filter - JobTitle: 'Scheduled import from Services' - # Sets whether the job will be recreated or not OPTIONAL - recreate: 1 - # Set the email address to send the alert to if not set site admin email is used OPTIONAL - email: 'admin@email.com' - # Parameters set on the recreated object OPTIONAL - construct: - # 1 or more Fieldname: 'value' sets be passed to the constructor OPTIONAL - repeat: 300 - title: 'Scheduled import from Services' - # Minimal implementation will send alerts but not recreate - AnotherTitle: - type: 'AJob' - filter: - JobTitle: 'A job' + properties: + defaultJobs: + # This key is used as the title for error logs and alert emails + ArbitraryName: + # The job type should be the class name of a job REQUIRED + type: 'ScheduledExternalImportJob' + # This plus the job type is used to create the SQL query REQUIRED + filter: + # 1 or more Fieldname: 'value' sets that will be queried on REQUIRED + # These can be valid ORM filter + JobTitle: 'Scheduled import from Services' + # Sets whether the job will be recreated or not OPTIONAL + recreate: 1 + # Set the email address to send the alert to if not set site admin email is used OPTIONAL + email: 'admin@email.com' + # Parameters set on the recreated object OPTIONAL + construct: + # 1 or more Fieldname: 'value' sets be passed to the constructor OPTIONAL + repeat: 300 + title: 'Scheduled import from Services' + # Minimal implementation will send alerts but not recreate + AnotherTitle: + type: 'AJob' + filter: + JobTitle: 'A job' ``` ## Configuring the CleanupJob diff --git a/code/services/QueuedJobService.php b/code/services/QueuedJobService.php index 7dc734e6..e8d22534 100644 --- a/code/services/QueuedJobService.php +++ b/code/services/QueuedJobService.php @@ -88,7 +88,7 @@ class QueuedJobService { * Config controlled list of default/required jobs * @var Array */ - public $defaultJobs; + public $defaultJobs = array(); /** * Register our shutdown handler @@ -325,6 +325,7 @@ public function checkJobHealth($queue = null) { */ public function checkdefaultJobs($queue = null) { $queue = $queue ?: QueuedJob::QUEUED; + if (count($this->defaultJobs)) { $activeJobs = QueuedJobDescriptor::get()->filter(array( @@ -349,8 +350,10 @@ public function checkdefaultJobs($queue = null) { )); if (!$job->count()) { + SS_Log::log("Default Job config: $title was missing from Queue and has been re-added", SS_Log::ERR); Email::create() - ->setTo(isset($jobConfig['email']) ? $jobConfig['email'] : Email::config()->admin_email) + ->setTo(isset($jobConfig['email']) ? $jobConfig['email'] : Config::inst()->get('Email', 'queued_job_admin_email')) + ->setFrom(Config::inst()->get('Email', 'queued_job_admin_email')) ->setSubject('Default Job "' . $title . '" missing') ->populateTemplate(array('Title' => $title, 'Site' => Director::absoluteBaseURL())) ->populateTemplate($jobConfig) @@ -358,7 +361,7 @@ public function checkdefaultJobs($queue = null) { ->send(); if (isset($jobConfig['recreate']) && $jobConfig['recreate']) { - if (!isset($jobConfig['construct']) || !isset($jobConfig['startDateFormat']) || !isset($jobConfig['startTimeString'])) { + if (!array_key_exists('construct', $jobConfig) || !isset($jobConfig['startDateFormat']) || !isset($jobConfig['startTimeString'])) { SS_Log::log("Default Job config: $title incorrectly set up. Please check the readme for examples", SS_Log::ERR); continue; }