-
Notifications
You must be signed in to change notification settings - Fork 466
Description
Describe the feature
The task scheduler syntax isn't very friendly and has caused issues in the past.
For a next big release, it's better to discard the code and move to the Laravel scheduler, which supports better configurations and the usage of a CRON syntax.
Extra reasons
If a plugin wants to run scheduled tasks, it needs to provide a scheduledTasks.xml
file, and also attach itself to the Acron
plugin. After installing such plugin, the administrator of a journal, which is using CRON instead of the Acron plugin, will also need to add a new entry at CRON
to execute the plugin's scheduledTasks.xml
.
- This is a bit counter-intuitive, the Acron shouldn't be any simpler than using CRON after both are setup.
- The "registration" should be unified, the executor just needs to have access to the list of tasks and their execution periods.
This is a follow-up of #8921
Also considering #7940
Plugins to update
- pkp/ojs · classes/plugins/PubObjectsExportPlugin.php
- pkp/usageStats · UsageStatsPlugin.inc.php [NOT REQUIRED AS FUNCTIONALITY MOVED TO CORE IN 3.4.0]
- pkp/pln · PlnPlugin.php
- pkp/crossrefReferenceLinking · CrossrefReferenceLinkingPlugin.php
- pkp/ops · classes/plugins/PubObjectsExportPlugin.php
- medra . MedraDoiDataMigration.php
PRs
- pkp-lib --> pkp/pkp-lib#9678 Replacing task schedular with laravel scheduler #10107
- ojs --> pkp/pkp-lib#9678 Replacing task schedular with laravel scheduler ojs#4332
- omp --> pkp/pkp-lib#9678 Replacing task schedular with laravel scheduler omp#1657
- ops --> pkp/pkp-lib#9678 Replacing task schedular with laravel scheduler ops#738
- acron --> pkp/pkp-lib#9678 make acron non functional acron#10 [Making acron non-functional]
- pln --> pkp/pkp-lib#9678 Laravel schedule task compatiable pln#92
- crossrefReferenceLinking --> pkp/pkp-lib#9678 Laravel schedule task compatiable crossrefReferenceLinking#26
- medra --> pkp/pkp-lib#9678 Laravel schedule task compatiable medra#29
Implementation Details
Changes are as following :-
- the XML based task scheduler is removed and moved to use the laravel like task scheduling approach, see at https://laravel.com/docs/11.x/scheduling . To register a schedule task that shared by all app , register it in
PKP\scheduledTask\PKPScheduler
and only app specific ones inAPP\scheduler\Scheduler
. - The old schedule tool
tools/runScheduledTasks.php
has been removed and we now have few different command to run schedules as :-
php lib/pkp/tools/scheduler.php run # Run any pending schedule task
php lib/pkp/tools/scheduler.php list # List all schedule tasks registered
php lib/pkp/tools/scheduler.php work # Run the schedule tasks as daemon, useful for local dev rather than to set up a crontab
php lib/pkp/tools/scheduler.php test # Allow the run specific schedule task from the list, useful for devs to test during development
Better to run php lib/pkp/tools/scheduler.php usage
to see all available options.
3. The Acron plugin
has been removed and the functionality to run schedule task on web based request has been moved to core . To enable the web based schedule task running , need to add the following in config.inc.php
file :-
;;;;;;;;;;;;;;;;;;;;;;;;;;
; Schedule Task Settings ;
;;;;;;;;;;;;;;;;;;;;;;;;;;
[schedule]
; Whether or not to turn on the built-in schedule task runner
;
; When enabled, schedule tasks will be processed at the end of each web
; request to the application.
;
; Use of the built-in schedule task runner is highly discouraged for high-volume
; sites. Use your operational system's task scheduler instead, and configure
; it to run the task scheduler every minute.
; Sample for the *nix crontab
; * * * * * php lib/pkp/tools/scheduler.php run >> /dev/null 2>&1
;
; See: <link-to-documentation>
task_runner = On
; How often should the built-in schedule task runner run scheduled tasks at the
; end of web request life cycle (value defined in seconds).
;
; This configuration will only have effect for the build-it task runner, it doesn't apply
; to the system crontab configuration.
;
; The default value is set to 60 seconds, a value smaller than that might affect the
; application performance negatively.
task_runner_interval = 60
; When enabled, an email with the scheduled task result will be sent only when an error
; has occurred. Otherwise, all tasks will generate a notification.
scheduled_tasks_report_error_only = On
- the previously existed config option
scheduled_tasks_report_error_only
has been moved fromgeneral
section to newly added sectionschedule
inconfig.inc.php
- config option
scheduled_task
from sectiongeneral
has been removed in favour of Use or remove scheduled_tasks flag in config.inc.php #7940 . - Plugins now also can not register schedule tasks as
XML
but to use the laravel based scheduler convention . To plugins have own scheduler, it need to implement thePKP\plugins\interfaces\HasTaskScheduler
and register the task, for example :
/**
* @copydoc \PKP\plugins\interfaces\HasTaskScheduler::registerSchedules()
*/
public function registerSchedules(PKPScheduler $scheduler): void
{
$scheduler
->addSchedule(new DOAJInfoSender())
->everyMinute()
->name(DOAJInfoSender::class)
->withoutOverlapping();
}