The docs say:

> * - 'queue name': The name of the queue to use to queue this task. Must
* contain a valid queue name, declared by hook_cron_queue_info().
* If queue name is given, worker callback will be ignored.

AFAICT this is wrong on two counts.

1.

/**
 * Implements hook_cron_queue_info().
 *
 * Provide queue worker information for jobs declared in
 * hook_cron_job_scheduler_info().
 */
function job_scheduler_cron_queue_info() {
  $queue = array();
  foreach (job_scheduler_info() as $name => $info) {
    if (!empty($info['jobs']) && !empty($info['queue name'])) {
      $queue[$info['queue name']] = array(
        'worker callback' => 'job_scheduler_cron_queue_worker',
        'time' => 60, // Some reasonable default as we don't know
      );
    }
  }
  return $queue;
}

This hook implementation seems to be taking care of declaring queues to Drupal core, based on hook_cron_job_scheduler_info().

This contradicts this statement:

> Must contain a valid queue name, declared by hook_cron_queue_info().

There is the matter that hook_cron_queue_info() skips a scheduler if it has no 'jobs' property. However, AFAICT, if a scheduler info has no jobs, then job_scheduler_rebuild_scheduler() doesn't write anything to the database anyway.

2.

> If queue name is given, worker callback will be ignored

If a queue name is given, then when the scheduler runs, it doesn't execute the worker callback. Instead, it queues a new item in the Drupal queue.

This uses the queue callback job_scheduler_cron_queue_worker(). job_scheduler_cron_queue_worker() executes the job, and executing the job calls the job's worker callback!

So that bit of the docs is wrong too.

Comments

bmelvin1’s picture

It looks like there are three patterns supported by this module, even though only two are documented in README.

Pattern 1: The Client module declares one or more job schedulers, each having a set of jobs and a callback function. In this pattern, jobs are executed (callback function is called) during JobScheduler’s cron_hook. The system queue is not used. To employ this pattern, Client's implementation of hook_cron_job_scheduler_info should declare 'worker callback' and 'jobs' (but not ‘queue name’) for each scheduler.

Pattern 2: The Client module declares and controls its own queues. JobScheduler enqueues jobs instead of executing them. To employ this pattern, Client should declare queues in hook_cron_queue_info. Client's implementation of hook_cron_job_scheduler_info should provide ‘queue name’ for each queue/scheduler. Pattern 2 is used by the Feeds module.

Pattern 3: (Not documented in README) JobScheduler enqueues jobs instead of executing them but, unlike Pattern 2, queues are declared by JobScheduler. To employ this pattern, Client module’s implementation of hook_cron_job_scheduler_info should declare 'worker callback', 'jobs' and ‘queue_name’ for each job scheduler.

Given the three distinct patterns, it would be difficult to write a clear set of comments for hook_cron_job_scheduler_info! Maybe it would be less misleading to have a comment that says "look at the README file"? And add Pattern 3 to the README.