1

I have a need for a function to run every N minutes (it doesn't need to be EXACTLY every N minutes, but it should still occur within a reasonable amount of time, maybe N+/- 5 minutes)

I've been bouncing around between the DrupalQueue class, job_scheduler, rules, actions, etc., and each time it seems like I run into a wall.

My current set up is that I use job_scheduler_trigger. I seem to have it setup correctly (using a basic UI created action of "Send email"), and I have it set to go every 5 minutes, but it NEVER fires. The "Next" run time just keeps incrementing itself properly, but the "Last" run time is always "Never". I have no idea what I'm doing wrong, or even if this is the best way to go about it. enter image description here

5
  • What kind of function is it? If it can be done through code, then you can just create a PHP file which bootstraps Drupal and performs your tasks. This then can be called from a crontab (sudo crontab -e) to run every 5 minutes :) That's provided you have shell access to your server
    – Beebee
    Sep 10 '15 at 20:53
  • How do you fire your cron? Without it firing at least every 5 minutes, no Drupal system will be able to fire anything every 5 minutes. I hope you knew that already, but your question doesn't show it.
    – Mołot
    Sep 10 '15 at 21:18
  • Correction: you don't need to fire cron if your solution provides something for you to fire instead, but you do need to fire something from the outside.
    – Mołot
    Sep 10 '15 at 21:26
  • Another option is using drush and creating a custom task and then using crontab on your system.
    – ropic
    Sep 11 '15 at 0:16
  • I ended up scaling it back a bit (at least as far as the number of involved modules went.) I added a Drush command to my already-in-development module, then altered the crontab for the apache user to fire the command every 5 minutes. Jan 7 '16 at 19:56
1

Using Rules and Rules scheduler (submodule of Rules) seems to me "a" valid approach.

What you actually need to do is a minor variation of what is explained in the tutorial Hourly tasks using rules scheduler: in your case you should use an offset of 5 minutes (instead of only after 1 hour). And you need to run cron every 5 minutes also (not hourly as in that tutorial).

And as explained also in that tutorial: Initially execute the component manually (from then on every other 5 minutes the rule will be executed again).

Note: How to schedule a regular job using Rules in Drupal 7 is another tutorial that covers this topic.

1
  • This seems valid, but I went with a different approach. Jan 7 '16 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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