Skip to content

Commit

Permalink
Merge pull request #135 from stephenmcm/fix-defaultjobs
Browse files Browse the repository at this point in the history
Fix(defaultJobs) config now loads correctly. Add SS_Log of missing jo…
  • Loading branch information
nyeholt authored Jul 19, 2017
2 parents 308d0a7 + 35d1ade commit 6e7bd17
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]'
# 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: '[email protected]'
# 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
Expand Down
9 changes: 6 additions & 3 deletions code/services/QueuedJobService.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class QueuedJobService {
* Config controlled list of default/required jobs
* @var Array
*/
public $defaultJobs;
public $defaultJobs = array();

/**
* Register our shutdown handler
Expand Down Expand Up @@ -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(
Expand All @@ -349,16 +350,18 @@ 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)
->setTemplate('QueuedJobsDefaultJob')
->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;
}
Expand Down

0 comments on commit 6e7bd17

Please sign in to comment.