Skip to content

Commit

Permalink
Merge branch '3'
Browse files Browse the repository at this point in the history
  • Loading branch information
dhensby committed Nov 8, 2017
2 parents 646ea85 + 4ba817c commit c9d7672
Show file tree
Hide file tree
Showing 17 changed files with 435 additions and 44 deletions.
16 changes: 8 additions & 8 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of SilverStripe nor the names of its contributors may be used to endorse or promote products derived from this software
* Neither the name of SilverStripe nor the names of its contributors may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
81 changes: 80 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# SilverStripe Queued Jobs Module

[![Build Status](https://travis-ci.org/symbiote/silverstripe-queuedjobs.svg?branch=master)](https://travis-ci.org/symbiote/silverstripe-queuedjobs)
[![Scrutinizer](https://scrutinizer-ci.com/g/symbiote/silverstripe-queuedjobs/badges/quality-score.png)](https://scrutinizer-ci.com/g/symbiote/silverstripe-queuedjobs/)


## Maintainer Contact

Marcus Nyeholt

marcus@symbiote.com.au
<marcus (at) symbiote (dot) com (dot) au>

## Requirements

Expand Down Expand Up @@ -128,6 +130,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}计划执行'
13 changes: 13 additions & 0 deletions src/Controllers/QueuedJobsAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use SilverStripe\Forms\GridField\GridFieldDataColumns;
use SilverStripe\Forms\TextareaField;
use SilverStripe\ORM\DataList;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor;
use Symbiote\QueuedJobs\Forms\GridFieldQueuedJobExecute;
Expand Down Expand Up @@ -64,6 +65,12 @@ class QueuedJobsAdmin extends ModelAdmin
'EditForm'
];

/**
* European date format
* @var string
*/
private static $date_format_european = 'dd/MM/yyyy';

/**
* @var QueuedJobService
*/
Expand Down Expand Up @@ -171,6 +178,12 @@ public function createjob($data, Form $form)
$params = isset($data['JobParams']) ? explode(PHP_EOL, $data['JobParams']) : array();
$time = isset($data['JobStart']) && is_array($data['JobStart']) ? implode(" ", $data['JobStart']) : null;

// If the user has select the European date format as their setting then replace '/' with '-' in the date string so PHP
// treats the date as this format.
if (Member::currentUser()->DateFormat == self::$date_format_european) {
$time = str_replace('/', '-', $time);
}

if ($jobType && class_exists($jobType)) {
$jobClass = new ReflectionClass($jobType);
$job = $jobClass->newInstanceArgs($params);
Expand Down
Loading

0 comments on commit c9d7672

Please sign in to comment.