Hi All,

I create a module to invoke the drupal cron hook, but if then, it will use the drupal cron settings. Is there any way to invoke a cron job with my own settings? I want this module to check the data in database, so I think it is better if it is a module (because we can invoke the db api very easy in a module).

So my purpose is let the drupal cron run one time per hour, and let my custom crons one time per day.
Any suggestion is welcome.

Comments

jaypan’s picture

Yes and no. You have to set cron to run once per hour, but you can set a variable in your hook_cron() so that your own hook only executes once a day:

function my_module_cron()
{
  $last_run = variable_get('my_module_last_cron_run', 0);
  if(time() - $last_run > 86400) // this conditional will only execute if it has been more than one day since your last cron run
  {
    variable_set('my_module_last_cron_run', time());
    // do your cron stuff here
  }
}

Contact me to contract me for D7 -> D10/11 migrations.

z.b.q’s picture

Thank you very much.