3

I have several rules that need to be fired after certain events.

When an event occurs and the rule starts execution, and something happens to the server, it may not finish.

Is there a way to make sure a rule will always execute?

I am asking for a method like a transaction occurs in MySQL. I need to be sure that a rule is executed to ensure data integrity.

1 Answer 1

2

To my knowledge there is no such thing as "make sure a rule will always execute?" (as in your question). However, by using the Message module, you can create your own custom "Events logging" (to register things that happened in a site).

A great sample of this you can find in Commerce Kickstart, which uses the Commerce Message module, to create such "Events logging". In this case in the format of an Order History, as shown in this screenprint (from this module's project page).

So in your case, if you'd create an appropriate events logging of all sorts of Rules related Events that you're interested in (= are critical enough?), then at least you'd have appropriate data you can use to investigate if anything went wrong.

To actually do so, for any of your Rules, you could add these Rules Actions to them:

  • create a "Start Rules Action"-message (as the very first action).
  • create a "Stop Rules Action"-message (as the very last action).

With that, for any set of Rules Actions that started executing, you can check if you have 2 corresponding messages.

Here is a variation that might work also: instead of creating such "Stop Rules Action" message, you could also use the Flag module to flag the corresponding "Start Rules Action" (the Message module creates messages as entities, so you can flag them for sure). Such flagging would indicate that the set of Rules Actions completed without problems. And to list all the groups of Rules Actions that were interrupted, you'd just have to use the Views module to report about all "Start Rules Action" messages that were NOT flagged ... Piece of cake, no?

Attention: this covers the part related to Rules Actions, not (yet) something like "what are all Rules Events that were triggered but for which not even 1 Rules Action (= create the start-message) had started (because of some kind of interruption).

4
  • Thank you for your elaboration. I am also doing a similar check for certain rules. But it is very difficult to implement such mechanism for many rules in a system. This may cause problems in data integrity and I think almost all Drupal systems using rules are susceptible to this. Commented Nov 22, 2016 at 10:30
  • 1
    @SinanErdem for me having "many rules" is not a reason to not use such approach (it's just a matter of time to get each of them adapted). I don't understand why this may cause problems in data integrity. Though I do agree that all (not just "almost all") Drupal systems are susceptible to this. Which is also why afer reading your question I got an idea for a new Rules related wrapper-module (similar to how the execution of online transactions in a mainframe environment work ... with checkpoints, unit of work, etc). Commented Nov 22, 2016 at 10:39
  • I couldnt explain myself correctly. I wanted to say, difilculty/absence of that kind of a system causes data integrity problems. Such a tool as you suggest would be very helpful in every rules environment. Commented Nov 22, 2016 at 16:29
  • 1
    @SinanErdem : I fully agree, and I bet that anyone who comes up with a robust solution for that, is going to get a lot of interest from the huge Drupal sites. Compare it to banking transactions (running on a Mainframe), where failure is not an option. Commented Nov 22, 2016 at 18:02

Your Answer

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

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