1

I am building Drupal 7 Custom Module, my module needs to have cron job running on specific time, instead of the default cron time. How do I implement this?

This is my code for cron :

function mymodule_cron() {
    mymodule_data_process();
}

1 Answer 1

1

You can't. Drupal 7 does not provide this functionality. You have two options:

  1. In your mymodule_cron(), test if it is after specified time, and at least arbitrary number of hours after previous run (like, 20?). That way your processing will run almost every day, no earlier than specified hour.

  2. Make your module require Elysia Cron and use it's scheduling capabilities. That way you will get your code executed everyday, at specified time (5 minutes resolution if Elysia is configured as suggested in their documentation).

Important: You cannot assume your task will be executed at specific time. It will be executed at first opportunity after the time you specified, whenever, if ever, such opportunity happens. Elysia Cron is pretty good at it, true, but exact time of execution can't be assumed guaranteed. Highly probable, to some resolution, maybe. But never guaranteed.

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.