Last updated 14 March 2017. Created on 11 April 2013.
Edited by COBadger, mradcliffe, dasjo, Jeff Veit. Log in to edit this page.

Rules Scheduler allows you to schedule the execution of a Component. While you can map the date of execution to a field, there's no way to calculate a date and pass it to the scheduler, but you can do this programatically.

Before using the code below, you will need to enable the rules_scheduler submodule (ships with 'rules' module) and set up a Component in the Rules UI. You may need to set up parameters for the component if you want it to operate on an entity. For example you might set up a parameter named 'user_to_delete' of type User to pass to an action for blocking a user.

To schedule the execution of a component:

  $component = 'machine_name_of_the_component';
  $task_identifier = 'a_unique_task_identifier';
  rules_action('schedule', array('component' => $component))->executeByArgs(array(
    'date' => $timestamp,
    'identifier' => $task_identifier,
    // Add component parameters, prefixed with 'param_'
    'param_x' => $x,
    'param_y' => $y,

Deleting a scheduled rule component

  rules_action('schedule_delete', array('component' => $component))->executeByArgs(array(
    'task' => $task_identifier,

Looking for support? Visit the forums, or join #drupal-support in IRC.


supriyarajgopal’s picture

This seems to be exactly what I was searching for..but where do I include the above code?In .module file?Under which hook?

Thanking you.

supriyarajgopal’s picture

I found the answer..
You have to place this code in an appropriate hook.
Eg:- If you want to schedule the rule component when cron is run, you place this code in hook_cron()..or if you want it when a node is insert, then in hook_node_insert()
Just in case this helps anyone :)

Maestro232’s picture

I'm looking to essentially loop through any existing scheduled rules that have not yet fired and retrieve the time each is scheduled to fire. How would I do this?