Commit 6d26429c authored by m.lebedev's avatar m.lebedev Committed by intrafusion
Browse files

Issue #3098709 by m.lebedev: Correct instructions in README.txt?

parent 6a3179f5
......@@ -12,47 +12,51 @@ Usage
Declare scheduler.
function example_cron_job_scheduler_info() {
$schedulers = array();
$schedulers['example_unpublish'] = array(
$schedulers = [];
$schedulers['example_unpublish'] = [
'worker callback' => 'example_unpublish_nodes',
);
];
return $schedulers;
}
Add a job.
$job = array(
$job = [
'name' => 'example_unpublish',
'type' => 'story',
'id' => 12,
'period' => 3600,
'periodic' => TRUE,
);
JobScheduler::get('example_unpublish')->set($job);
];
$service = \Drupal::service('job_scheduler.manager');
$service->set($job);
Work off a job.
function example_unpublish_nodes($job) {
function example_unpublish_nodes(\Drupal\job_scheduler\Entity\JobSchedule $job) {
// Do stuff.
}
Remove a job.
$job = array(
$job = [
'name' => 'example_unpublish',
'type' => 'story',
'id' => 12,
);
JobScheduler::get('example_unpublish')->remove($job);
];
$service = \Drupal::service('job_scheduler.manager');
$service->remove($job);
Optionally jobs can declared together with a schedule in a hook_cron_job_scheduler_info().
function example_cron_job_scheduler_info() {
$schedulers = array();
$schedulers['example_unpublish'] = array(
$schedulers = [];
$schedulers['example_unpublish'] = [
'worker callback' => 'example_unpublish_nodes',
'jobs' => array(
array('type' => 'story', 'id' => 12, 'period' => 3600, 'periodic' => TRUE),
)
);
'jobs' => [
['type' => 'story', 'id' => 12, 'period' => 3600, 'periodic' => TRUE],
],
];
return $schedulers;
}
......@@ -61,13 +65,13 @@ Example of job with crontab.
// This will create a job that will be triggered from monday to friday, from january to july, every two hours
function example_cron_job_scheduler_info() {
$schedulers = array();
$schedulers['example_unpublish'] = array(
$schedulers = [];
$schedulers['example_unpublish'] = [
'worker callback' => 'example_unpublish_nodes',
'jobs' => array(
array('type' => 'story', 'id' => 12, 'crontab' => '0 */2 * january-july mon-fri', 'periodic' => TRUE),
)
);
'jobs' => [
['type' => 'story', 'id' => 12, 'crontab' => '0 */2 * january-july mon-fri', 'periodic' => TRUE],
],
];
return $schedulers;
}
......@@ -80,53 +84,30 @@ Optionally, at the scheduled time Job Scheduler can queue a job for execution,
rather than executing the job directly. This is useful when many jobs need to
be executed or when the job's expected execution time is very long.
More information on Drupal Queue: http://api.drupal.org/api/group/queue/7
More information on Drupal Queue: https://api.drupal.org/api/drupal/core%21core.api.php/group/queue/8.0.x
Instead of declaring a worker callback, declare a queue name.
Declare a queue name and a worker callback.
function example_cron_job_scheduler_info() {
$schedulers = array();
$schedulers['example_unpublish'] = array(
$schedulers = [];
$schedulers['example_unpublish'] = [
'queue name' => 'example_unpublish_queue',
);
return $schedulers;
}
This of course assumes that you have declared a queue. Notice how in this
pattern the queue callback contains the actual worker callback.
function example_cron_queue_info() {
$schedulers = array();
$schedulers['example_unpublish_queue'] = array(
'worker callback' => 'example_unpublish_nodes',
);
];
return $schedulers;
}
Work off a job: when using a queue, Job Scheduler reserves a job for one hour
giving the queue time to work off a job before it reschedules it. This means
that the worker callback needs to reset the job's schedule flag in order to
allow renewed scheduling.
function example_unpublish_nodes($job) {
function example_unpublish_nodes(\Drupal\job_scheduler\Entity\JobSchedule $job) {
// Do stuff.
// Set the job again so that its reserved flag is reset.
JobScheduler::get('example_unpublish')->set($job);
}
Example
=======
Optionally, can specify the name and the execution time of the queue.
See Feeds module.
Hidden settings
===============
Hidden settings are variables that you can define by adding them to the $conf
array in your settings.php file.
Name: 'job_scheduler_class_' . $name
Default: 'JobScheduler'
Description: The class to use for managing a particular schedule.
function example_cron_job_scheduler_queue_info() {
$schedulers = [];
$schedulers['example_unpublish_queue'] = [
'title' => 'Example unpublish nodes',
'time' => 120,
];
return $schedulers;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment