Skip to content

Replace task scheduler by Laravel scheduler #9678

@jonasraoni

Description

@jonasraoni

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

PRs

Implementation Details
Changes are as following :-

  1. 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 in APP\scheduler\Scheduler.
  2. 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
  1. the previously existed config option scheduled_tasks_report_error_only has been moved from general section to newly added section schedule in config.inc.php
  2. config option scheduled_task from section general has been removed in favour of Use or remove scheduled_tasks flag in config.inc.php #7940 .
  3. 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 the PKP\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();
    }

Sub-issues

Metadata

Metadata

Assignees

Labels

Enhancement:3:MajorA new feature or improvement that will take a month or more to complete.Housekeeping:1:TodoAny dependency management or refactor that would be nice to have some day.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions