We have a new requirement where we need to run a job on a daily basis. We have setup cron to run every 1 hour. The goal is to have cron ron every 1 hour, but we want a specific job to run only if 1 day (24hours) has past since last run.
We used to use the Variables table to store the time the job was last run, but we need to change this to use the cache table. Below is the code (mymodule.module) we were reviewing, but it is not creating a cache table and not storing the appropriate date. So we need assistance in figuring out if we are using the correct logic so the job runs once everyday.
Note: $cache->data below is actually the last time the job ran.
mymodule_cron() {
$data = '';
if($cache = cache_get('last-run')) {
$data = $cache->data;
if($data <= strtotime('-1 day')) {
//call helper function to perform some logic
_some_func();
$data = time();
//set update date in cache
cache_set('last-run', $data, 'cache'));
}
}
}