Gallery3:Modules:scheduler - Gallery Codex
Personal tools

Gallery3:Modules:scheduler

From Gallery Codex

About

Schedule tasks to run at specific times and intervals.

Description

Adds a schedule button to the maintenance task of existing maintenance items.

It's worth noting that version 1, which is available from the gallery3-contrib library, does not require the use of crontab. It will run a portion of the maintenance task with each http request after the request has been written to the browser.

Screen shots

Admin-Maint shed.png

Installation

This module may be downloaded from the Gallery forums here (version 2 beta 1).
More details and operation can be found in the forums.

To install, extract the "scheduler" folder from the zip file into your Gallery 3 modules folder.
Afterwards log into your Gallery web site as an administrator and activate the module in the Admin -> Modules menu.
Then, Admin -> Maintenance is overloaded by this module to provide scheduler functionality also.

To enable the cron functions of this module, enter this into your server's crontab:

  */15 * * * * /usr/bin/wget http://www.yourdomain.com/gallery3/modules/scheduler/cron.php

Read more about cron expressions for more information on customising the cron expression.

Developers

Developers can use this module's functionality in their own modules to set tasks to be executed once, or frequently, by the crontab. Once this module has been enabled, it prevents tasks from running on the gallery_shutdown() event, thus improving the performance of the front-end.

Checking that scheduler is enabled is simple, just check:

  if (module::is_active("scheduler")) {
      // can schedule
  }
  else {
      // can't schedule
  }

To schedule a one-off task, do:

  $task = task::create($task_def, array());
  $schedule = ORM::factory("schedule");
  $schedule->add_task($task);

This will add the task to a list of tasks scheduled to run immediately (on next cron execution). It currently does not allow you to specify an execution time, or an execution frequency higher than one-off. This is planned to be implemented, however, before the module is no longer in beta.

To ensure that a task returned via available_tasks() can only be executed there-and-then, or only scheduled, ensure you provide flags to the Task_Definition. Example:

  $task_def = Task_Definition::factory()
                  ->callback("helper::function")
                  ->name(t("Task name"))
                  ->description(t("Task description"))
                  ->severity(log::SUCCESS)
                  ->set_flags(Task_Definition::CAN_RUN_NOW);

Or:

  $task_def = Task_Definition::factory()
                  ->callback("helper::function")
                  ->name(t("Task name"))
                  ->description(t("Task description"))
                  ->severity(log::SUCCESS)
                  ->set_flags(Task_Definition::CAN_SCHEDULE);

Not specifying any flags allows the task to be executed both there-and-then, or scheduled. It's also important that you wrap the defintion factory call in an

  if (module::is_active("scheduler")) {}

statement, unless your module will fail to activate unless the scheduler module is active also (errored on this condition in your module's can_activate() function).



Notes

advertisements