0

I'm trying to set up a cron queue, but for some reason, I don't manage to get this done.

Here is what I have so far:

function mymodule_cron() {
    // Setup the queue
    $queue = DrupalQueue::get('import_jobs');
    // Create cache
    drupal_flush_all_caches();
}

function mymodule_cron_queue_info() {
    $queues['import_jobs'] = array(
    'worker callback' => '_import_all_jobs',
    'time' => 15, 
    );
    return $queues;
}

The _import_all_jobs function does it's work excellent, so nothing wrong with that. I use the Ultimate Cron module and my cron job is listed over there:

enter image description here

But for some reason, nothing happens... So I'm wondering what I do wrong...

2
  • Have you actually got Cron running on the server?
    – Chapabu
    Commented Apr 10, 2012 at 21:25
  • Yes, I've got Cron running on the server
    – Michiel
    Commented Apr 11, 2012 at 8:01

2 Answers 2

3

You need to add items to your queue. You have created a queue, but haven't added anything to it, so nothing is being done.

$queue->createItem($item);

$item will get passed to the queue callback function (_import_all_jobs).

I would suggest modifying _import_all_jobs to import an individual job (_import_job). Then $item would be a job added to the queue and you let DrupalQueue do its thing.

This article may be helpful: Cron Queues: Processing large amounts of data in cron

And here is some relevant Drupal documentation: Queue operations

2
  • That's what I figured, but what would the $item be? I don't need an array or something similar. All I need is the function _import_all_jobs to run on a cron job.
    – Michiel
    Commented Apr 11, 2012 at 8:02
  • In that case, it can be anything you want, like NULL.
    – mbomb007
    Commented Sep 17, 2019 at 13:33
0

If you are not processing multiple items, you could just run _import_all_jobs from the cron:

function mymodule_cron() {
    _import_all_jobs();

    // Create cache
    drupal_flush_all_caches();
}

But it seems like _import_all_jobs is doing multiple things and should be modified to work as a DrupalQueue, as I've suggested in my first answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.