Job Queue is a great module that would make some rules' actions performance friendly by adding function calls to a queue that is run on cron (thinking of mail to users of role...)
Why not have rules actions check if module jobqueue exists and then call :
job_queue_add($function, $description, $arguments = array(), $file = '', $no_duplicate = FALSE)

Or maybe add a checkbox on Action Form that says "queue this action on cron run".

What do you think ?

Comments

mitchell’s picture

Discussion over at job queue: #423834: Integrate Job Queue with Rules.

redben’s picture

@opensanta I saw the discussion at job queue (bye the way great a module!) before posting on rules issue queue. The reason i post this feature request here is that i think that if somethink should be done it is here and not on jobqueue, because it is rules that is going to be using a feature on job queue.
What are your thoughts ?

mitchell’s picture

Title: Integrate Rules With Job Queue if installed » Integrate with Queue API
Version: 6.x-1.x-dev » 7.x-2.x-dev
Component: Provided module integration » Rules Engine
fago’s picture

Component: Rules Engine » Provided module integration

Yep, that sounds useful. Not sure whether it should ship with rules though. Queue is in core, so from that point it should. However this is more an advanced feature which shouldn't confuse starters.

YK85’s picture

subscribing

mitchell’s picture

Component: Provided module integration » Rules Engine

Another issue with similar goals and UX considerations: #89181: Use queue API for node and comment, user, node multiple deletes

7wonders’s picture

This would be very handy as sometimes a rule being called will jam up other processes if the action is a lengthy one. For example, I had a rule being called on creation of nodes through a rest service with services 3, the rule was to perform some custom module imports, reverse geo lookups and other stuff through an execute php code action, so it takes some time. This prevented the rest response from being sent and giving timeout responses. SO, instead of sending the parameters directly to the custom module I sent them to a queue:

function custom_module_add2queue($p1, $p2, $p3) {
  // Put everything in a queue for processing.
  $item = array('p1' => $p1, 'p2' => $p2, 'p3' => $p3);
  $queue = DrupalQueue::get('custom_module');
  $queue->createItem($item);
}

Then the job is done on cron instead.

function custom_module_cron_queue_info() {
  $queues['custom_module'] = array(
    'worker callback' => 'custom_module_import', // This is the callback function for each queue item.
    'time' => 180, // This is the max run time per cron run in seconds.
  );
  return $queues;
}

Im pretty sure someone smarter than myself could put together a generic version of this so that different actions could be sent to "rules action queues" that are handled on cron.

bojanz’s picture

VBO allows you to enqueue a rules component on any number of entities.

mitchell’s picture

Component: Rules Engine » Rules Core
mitchell’s picture

Title: Integrate with Queue API » Improve usability of Rules' Queue API integration
Component: Rules Core » Scheduler
Issue tags: +Usability, +UX

Actually, Queue API integration is already provided by Rules Scheduler. The problem is that, even though it can be used to solve use cases like #7 and #1695018: Flag Javascript Toggle extremely slow with Rules, it's likely to be missed.

Perhaps, we could either try to solve this in rules_scheduler.info at the name and/or description, to make the availability of this functionality more obvious, or maybe in the same spirit of #1495718: Add option to convert a set of conditions or actions to a component, we could add an option to components in the actions list to "Convert to a scheduled operation" or "Convert to a queued operation". The effect would be to replace the "Evaluate component [x]" with the "Schedule a component for evaluation".

I think one major focus to consider is where/how we can replace the verb 'schedule' with 'queue'.

mitchell’s picture

Status: Active » Closed (duplicate)

Marking this as a duplicate of #1780484: Rename Scheduler to Queue Scheduler per #10.