Skip to content

Commit

Permalink
Merge branch '2.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
dhensby committed Nov 6, 2017
2 parents 646ea85 + 84cabea commit 8d5f8f4
Show file tree
Hide file tree
Showing 15 changed files with 409 additions and 32 deletions.
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,83 @@ Note - if you do NOT have this running, make sure to set `QueuedJobService::$use
so that immediate mode jobs don't stall. By setting this to true, immediate jobs will be executed after
the request finishes as the php script ends.

# Default Jobs

Some jobs should always be either running or queued to run, things like data refreshes or periodic clean up jobs, we call these Default Jobs.
Default jobs are checked for at the end of each job queue process, using the job type and any fields in the filter to create an SQL query e.g.

```
ArbitraryName:
type: 'ScheduledExternalImportJob'
filter:
JobTitle: 'Scheduled import from Services'
```
Will become:
```
QueuedJobDescriptor::get()->filter(array(
'type' => 'ScheduledExternalImportJob',
'JobTitle' => 'Scheduled import from Services'
));
```
This query is checked to see if there's at least 1 healthly (new, run, wait or paused) job matching the filter. If there's not and recreate is true in the yml config we use the construct array as params to pass to a new job object e.g:
```
ArbitraryName:
type: 'ScheduledExternalImportJob'
filter:
JobTitle: 'Scheduled import from Services'
recreate: 1
construct:
repeat: 300
contentItem: 100
target: 157
```
If the above job is missing it will be recreated as:
```
Injector::inst()->createWithArgs('ScheduledExternalImportJob', $construct[])
```
### Pausing Default Jobs
If you need to stop a default job from raising alerts and being recreated, set an existing copy of the job to Paused in the CMS.
### YML config
Default jobs are defined in yml config the sample below covers the options and expected values
```
Injector:
QueuedJobService:
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
By default the CleanupJob is disabled. To enable it, set the following in your YML:
Expand Down
10 changes: 5 additions & 5 deletions lang/ar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ ar:
MEMORY_RELEASE: 'ذاكرة إطلاق الوظائف و الانتظار (s% مستخدم)'
STALLED_JOB: 'الوظيفة المؤجلة'
STALLED_JOB_MSG: 'وظيفة باسم s% تبين أنها تعطلت. قد تم توقفها, من فضلك سجل الدخول لكى تتحقق منها'
TABLE_ADDE: تمت إضافته
TABLE_ADDE: 'تمت إضافته'
TABLE_MESSAGES: رسالة
TABLE_NUM_PROCESSED: تم
TABLE_STARTED: تم البدأ
TABLE_NUM_PROCESSED: 'تم'
TABLE_STARTED: 'تم البدأ'
TABLE_START_AFTER: 'ابدأ بعد'
TABLE_STATUS: الحالة
TABLE_TITLE: عنوان
Expand All @@ -33,14 +33,14 @@ ar:
ScheduledExecution:
EXECUTE_EVERY: 'قم بتنفيذ كل'
EXECUTE_FREE: 'محددة (بصيغة إس تى آر تو تايم من التنفيذ الأول)'
ExecuteEveryDay: يوم
ExecuteEveryDay: 'يوم'
ExecuteEveryFortnight: أسبوعان
ExecuteEveryHour: ساعة
ExecuteEveryMonth: شهر
ExecuteEveryWeek: أسبوع
ExecuteEveryYear: سنة
FIRST_EXECUTION: 'التنفيذ الأول'
NEXT_RUN_DATE: 'موعد التشغيل التالى'
ScheduleTabTitle: الجدول الزمني
ScheduleTabTitle: 'الجدول الزمني'
ScheduledExecutionJob:
Title: 'موعد التنفيذ المحدد ل {title}'
4 changes: 2 additions & 2 deletions lang/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ de:
JOB_EXCEPT: 'Auftrag hat einen ''%s'' Fehler verursacht in %s Zeile %s '
JOB_PAUSED: 'Auftrag pausiert um %s'
JOB_STALLED: 'Auftrag angehalten nach %s versuchen. Bitte überprüfen Sie den Auftrag.'
JOB_TYPE: 'Auftragstyp'
JOB_TYPE: Auftragstyp
JobsFieldTitle: Aufträge
STALLED_JOB: 'Angehaltener Auftrag'
STALLED_JOB_MSG: 'Der Auftrag %s scheint festzustecken. Er wurde angehalten. Bitte loggen Sie sich ein, um den Auftrag zu überprüfen.'
Expand All @@ -39,7 +39,7 @@ de:
EXECUTE_EVERY: 'Alle ausführen'
EXECUTE_FREE: 'Geplant (in strtotime-format nach dem ersten Ausführen)'
ExecuteEveryDay: Tag
ExecuteEveryFortnight: Zwei Wochen
ExecuteEveryFortnight: 'Zwei Wochen'
ExecuteEveryHour: Stunde
ExecuteEveryMinute: Minute
ExecuteEveryMonth: Monat
Expand Down
2 changes: 1 addition & 1 deletion lang/eo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ eo:
EXECUTE_EVERY: 'Plenumi ĉiun'
EXECUTE_FREE: 'Planita (en strtotime-formato ek de unua plenumo)'
ExecuteEveryDay: Tago
ExecuteEveryFortnight: Du semajnoj
ExecuteEveryFortnight: 'Du semajnoj'
ExecuteEveryHour: Horo
ExecuteEveryMinute: Minuto
ExecuteEveryMonth: Monato
Expand Down
4 changes: 2 additions & 2 deletions lang/fi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fi:
SINGULARNAME: 'Jonossa olevan tehtävän kuvaaja'
QueuedJobs:
JOB_PAUSED: 'Tehtävä pysäytetty aikaan %s'
JOB_TYPE: 'Tehtävätyyppi'
JOB_TYPE: Tehtävätyyppi
JobsFieldTitle: Tehtävät
STALLED_JOB: 'Pysäytetty työ'
STALLED_JOB_MSG: '%s tehtävä näyttää olevan seisahtunut. Se on nyt pysäytetty. Ole hyvä ja kirjaudu sisään tarkastellaksesi sitä'
Expand All @@ -26,7 +26,7 @@ fi:
ScheduledExecution:
EXECUTE_EVERY: 'Suorita joka'
ExecuteEveryDay: Päivä
ExecuteEveryFortnight: Kaksi viikkoa
ExecuteEveryFortnight: 'Kaksi viikkoa'
ExecuteEveryHour: Tunti
ExecuteEveryMonth: Kuukausi
ExecuteEveryWeek: Viikko
Expand Down
2 changes: 1 addition & 1 deletion lang/hr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ hr:
EXECUTE_EVERY: 'Izvrši svaki'
EXECUTE_FREE: 'Planirano (u strtotime formatu od prvog pokretanja)'
ExecuteEveryDay: dan
ExecuteEveryFortnight: dve nedjelje
ExecuteEveryFortnight: 'dve nedjelje'
ExecuteEveryHour: sat
ExecuteEveryMinute: minuta
ExecuteEveryMonth: mjesec
Expand Down
12 changes: 6 additions & 6 deletions lang/mi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ mi:
JOB_PAUSED: 'i okioki te mahi i %s'
JOB_STALLED: 'I auporoa te mahi i muri i ngā whakamātauranga %s - me tirotiro'
JOB_TYPE: 'Momo mahi'
JobsFieldTitle: Ngā Mahi
JobsFieldTitle: 'Ngā Mahi'
MEMORY_RELEASE: 'E tuku pūmahara ana te mahi, ka tataru (i whakamahia te %s)'
STALLED_JOB: 'Mahi Kua Auporoa'
STALLED_JOB_MSG: 'Te āhua nei, kua auporoa he mahi e kīia ana ko %s. Kua okioki, me takiuru anō kia tirohia'
TABLE_ADDE: I Tāpiritia
TABLE_ADDE: 'I Tāpiritia'
TABLE_MESSAGES: Karere
TABLE_NUM_PROCESSED: Kua Oti
TABLE_STARTED: I Tīmata
TABLE_NUM_PROCESSED: 'Kua Oti'
TABLE_STARTED: 'I Tīmata'
TABLE_START_AFTER: 'Tīmata Ā Muri'
TABLE_STATUS: Tūnga
TABLE_TITLE: Taitara
TABLE_TOTAL: Tapeke
QueuedJobsAdmin:
MENUTITLE: Ngā Mahi
MENUTITLE: 'Ngā Mahi'
ScheduledExecution:
EXECUTE_EVERY: 'Kawea Te Katoa'
EXECUTE_FREE: 'Kua whakaritea ( i te hōputu strtotime mai i te kawenga tuatahi)'
ExecuteEveryDay:
ExecuteEveryFortnight: Rua Wiki
ExecuteEveryFortnight: 'Rua Wiki'
ExecuteEveryHour: Haora
ExecuteEveryMonth: Marama
ExecuteEveryWeek: Wiki
Expand Down
57 changes: 57 additions & 0 deletions lang/ru.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
ru:
CreateQueuedJobTask:
Description: 'Задача используется для создания отложенного действия. Укажите тип задачи, укажите опциональный параметр "start" (обрабатывается функцией strtotime) для времени начала.'
DeleteObjectJob:
DELETE_JOB: Удалить
DELETE_OBJ2: 'Удалить {title}'
GenerateSitemapJob:
REGENERATE: 'Генерировать Google sitemap .xml файл'
ProcessJobQueueTask:
Description: 'Используется cron для выполнения отложенных задач.'
PublishItemsJob:
Title: 'Опубликовать вложенные объекты {title}'
QueuedJobDescriptor:
PLURALNAME: 'Дескрипторы отложенных задач'
SINGULARNAME: 'Дескриптор отложенной задачи'
QueuedJobRule:
PLURALNAME: 'Настройки отложенных задач'
SINGULARNAME: 'Настройки отложенной задачи'
QueuedJobs:
CREATE_JOB_TYPE: 'Создать задачу типа'
CREATE_NEW_JOB: 'Создать задачу'
JOB_EXCEPT: 'Произошла ошибка задачи %s в %s на строчке %s'
JOB_PAUSED: 'Задача остановлена %s'
JOB_STALLED: 'Задача замороженна после %s попыток - пожалуйста проверьте'
JOB_TYPE: 'Тип задачи'
JOB_TYPE_PARAMS: 'Параметры конструктора задачи'
JobsFieldTitle: Задачи
MEMORY_RELEASE: 'Задача ожидает освобождения памяти (%s использовано)'
STALLED_JOB: 'Замороженная задача'
STALLED_JOB_MSG: 'Задача %s заморожена. Задача была остановлена, войдите в систему для проверки'
START_JOB_TIME: 'Начать задачу в'
TABLE_ADDE: Добавлена
TABLE_MESSAGES: Сообщение
TABLE_NUM_PROCESSED: Выполнено
TABLE_STARTED: Начата
TABLE_START_AFTER: 'Начать после'
TABLE_STATUS: Статус
TABLE_TITLE: Название
TABLE_TOTAL: Итого
TIME_LIMIT: 'Очередь достигла лимита по времени и будет начата заново перед продолжением'
QueuedJobsAdmin:
MENUTITLE: Задачи
ScheduledExecution:
EXECUTE_EVERY: 'Выполнять каждые'
EXECUTE_FREE: 'Запланировано (в формате strtotime после первого выполнения)'
ExecuteEveryDay: День
ExecuteEveryFortnight: 'Две недели'
ExecuteEveryHour: Час
ExecuteEveryMinute: Минута
ExecuteEveryMonth: Месяц
ExecuteEveryWeek: Неделя
ExecuteEveryYear: Год
FIRST_EXECUTION: 'Первое исполнение'
NEXT_RUN_DATE: 'Дата следующего исполнения'
ScheduleTabTitle: 'Расписание'
ScheduledExecutionJob:
Title: 'Запланировано исполнение {title}'
22 changes: 11 additions & 11 deletions lang/zh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,38 @@ zh:
PublishItemsJob:
Title: '发布下列项 {title}'
QueuedJobDescriptor:
PLURALNAME: '排队作业描述符'
SINGULARNAME: '排队作业描述符'
PLURALNAME: 排队作业描述符
SINGULARNAME: 排队作业描述符
QueuedJobs:
JOB_EXCEPT: '作业导致例外 %s 位于 %s 的第 %s 行'
JOB_PAUSED: '作业在 %s 暂停'
JOB_STALLED: '%s 次尝试后作业停滞 —— 请检查'
JOB_TYPE: '工作类型'
JOB_TYPE: 工作类型
JobsFieldTitle: 作业
MEMORY_RELEASE: '工作正在释放内存并等待(%s 已用)'
STALLED_JOB: '呆滞任务'
STALLED_JOB: 呆滞任务
STALLED_JOB_MSG: '名为 %s 的工作似乎停滞不前。它已暂停,请登录查看'
TABLE_ADDE: 已添加
TABLE_ADDE: '已添加'
TABLE_MESSAGES: 消息
TABLE_NUM_PROCESSED: 完成
TABLE_STARTED: 已开始
TABLE_START_AFTER: '开始于'
TABLE_START_AFTER: 开始于
TABLE_STATUS: 状态
TABLE_TITLE: 标题
TABLE_TOTAL: 全部
TABLE_TITLE: '标题'
TABLE_TOTAL: '全部'
QueuedJobsAdmin:
MENUTITLE: 作业
ScheduledExecution:
EXECUTE_EVERY: '执行每'
EXECUTE_EVERY: 执行每
EXECUTE_FREE: '已调度(以首次执行的时间戳格式显示)'
ExecuteEveryDay:
ExecuteEveryFortnight: 两周
ExecuteEveryHour:
ExecuteEveryMonth:
ExecuteEveryWeek:
ExecuteEveryYear:
FIRST_EXECUTION: '第一次执行'
NEXT_RUN_DATE: '下一次运行日期'
FIRST_EXECUTION: 第一次执行
NEXT_RUN_DATE: 下一次运行日期
ScheduleTabTitle: 日程表
ScheduledExecutionJob:
Title: '{title}计划执行'
10 changes: 8 additions & 2 deletions src/Jobs/CleanupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public function process()
if (empty($staleJobs)) {
$this->addMessage("No jobs to clean up.");
$this->isComplete = true;
$this->reenqueue();
return;
}
$numJobs = count($staleJobs);
Expand All @@ -149,13 +150,18 @@ public function process()
IN (\'' . $staleJobs . '\')');
$this->addMessage($numJobs . " jobs cleaned up.");
// let's make sure there is a cleanupJob in the queue
$this->reenqueue();
$this->isComplete = true;
return;
}

private function reenqueue()
{
if (Config::inst()->get('Symbiote\\QueuedJobs\\Jobs\\CleanupJob', 'is_enabled')) {
$this->addMessage("Queueing the next Cleanup Job.");
$cleanup = new CleanupJob();
singleton('Symbiote\\QueuedJobs\\Services\\QueuedJobService')
->queueJob($cleanup, date('Y-m-d H:i:s', time() + 86400));
}
$this->isComplete = true;
return;
}
}
8 changes: 8 additions & 0 deletions src/Services/ImmediateQueueHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ public function startJobOnQueue(QueuedJobDescriptor $job)
{
$this->queuedJobService->runJob($job->ID);
}

/**
* @param QueuedJobDescriptor $job
*/
public function scheduleJob(QueuedJobDescriptor $job, $date)
{
$this->queuedJobService->runJob($job->ID);
}
}
Loading

0 comments on commit 8d5f8f4

Please sign in to comment.