0

I am sooo close to getting this to work, but cannot figure out why I cannot get my rule to repeat. It's driving me nuts.

I created a component that has an action item to generate send a newsletter using the simplenews module. It works just fine when I execute it manually, but I need this to repeat weekly.

I've read a ton about having it repeat by using the action "Schedule component evaluation" and this makes total sense, but it just isn't firing after the initial rule. Right now I am testing it with +2 minutes so that I can see if it works or not. Eventually I want to have it be +1 week. But if it's not working with 2 minutes it won't work with 1 week.

EDIT: Right now I am running cron manually to check to see if it's working and it's just not.

screenshot

2 Answers 2

0

Make sure you're running cron on demand to force your process to run every those 2 minutes, the way rules scheduler works is to create a hook_cron process that checks the dates:

function rules_scheduler_cron() {
  // Limit adding tasks to 1000 per cron run.
  $result = db_select('rules_scheduler', 'r', array('fetch' => PDO::FETCH_ASSOC))
    ->fields('r')
    ->condition('date', time(), '<=')
    ->range(0, 1000)
    ->execute();

  $queue = DrupalQueue::get('rules_scheduler_tasks');
  foreach ($result as $task) {
    // Add the task to the queue and remove the entry afterwards.
    if ($queue->createItem($task)) {
      db_delete('rules_scheduler')
        ->condition('tid', $task['tid'])
        ->execute();
      $task_created = TRUE;
    }
  }

  if (!empty($task_created)) {
    // hook_exit() is not invoked for cron runs, so register it as shutdown
    // callback for logging the rules log to the watchdog.
    drupal_register_shutdown_function('rules_exit');
    // Clear the log before running tasks via the queue to avoid logging
    // unrelated logs from previous cron-operations.
    RulesLog::logger()->clear();
  }
}
4
  • Thanks pcambra. I tried manually running cron to be able to see if it was working and it wouldn't even work after I did that. So I am still baffled as to why this isn't working.
    – Dan
    Jul 14, 2014 at 15:08
  • Could you provide the export of the rule? Also checking the rules_scheduler table would be something to do in case you've got issues there.
    – pcambra
    Jul 14, 2014 at 15:31
  • Well this is crazy, but maybe I was running it too fast. I change it to +10 minutes and it seems to be working now. Don't know why that is, but glad its working! By the way, your function above is giving me a white screen of death when the rule runs. Any idea why?
    – Dan
    Jul 14, 2014 at 16:32
  • The function I pasted above is exactly what rules scheduler executes every time cron runs, many things can cause a WSOD, but memory limits is the top #1 probability, check drupal.org/node/158043
    – pcambra
    Jul 14, 2014 at 19:01
0

Turned out that for some reason having such a short interval was the problem. After I extended it to +10 minutes it worked fine.

Your Answer

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

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