1

I have created a rule to sent the view results, by using this:

<?php
$view = views_get_view('VIEWNAME');
print $view->preview('default');
?>

But I want this Rules Action to occur every 8 hours.

My question: What should be the "React on event" for this rule?

Edit: Based on the suggested answer, I'm now also using the Rules once per day module. Here is my rule (in rules export format):

{ "rules_send_emails_to_fuel_company_approved_client_list" : {
    "LABEL" : "Send emails to fuel company approved client list",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "php", "mimemail", "rules_onceperday" ],
    "ON" : { "once_per_day" : [] },
    "DO" : [
      { "mimemail" : {
          "key" : "somebody@example.com",
          "to" : "ok",
          "subject" : "ok",
          "body" : "\u003C?php\r\n$view = views_get_view(\u0027calling_agent_summary\u0027);\r\nprint $view-\u003Epreview(\u0027default\u0027);\r\n?\u003E",
          "language" : [ "" ]
        }
      }
    ]
  }
}

But I'm still not receiving any emails. So I wonder what might be the cause of this.

  • 1
    Thanks for the update. I'm not (yet) familiar with rules integration and mimelail, but a few remarks: (1) are you sure you want to publish your email here (replace it be a fake eMail id to avoid spammers ...) (2) are you sure cron has run already (try to indicate that somehow in your update if so) (3) the "to" in your rules action (= ok) looks very strange to me (should that not be some email id)? – Pierre.Vriens Apr 28 '16 at 5:45
  • 1
    I really think bullet (3) in my prior comment requires more investigation from your part. Have a look at the equivalent "to" value in the rules example in drupal.stackexchange.com/questions/187586 ... that's a token containing a real eMail value.Moreover, I think the "key" you are using might need reviewing also (if the same rule is triggered multiple times, it is not unique anymore, which seems like not a healthy situation, and might lead to unpredictable behaviours). PS: I "like" the edited eMail Id you now used ... – Pierre.Vriens Apr 28 '16 at 5:57
  • 1
    I think you are right. in 'to' i need to put my Email id. I have changed it on my rule. I hope it will works now. Thanks for you time and suggestion. – DRUPWAY Apr 28 '16 at 6:04
1

Option 1: Using Rules and Rules Scheduler

Use the Rules module and Rules scheduler (submodule of Rules). What you actually need to do is a minor variation of what is explained in the tutorial Hourly tasks using rules scheduler: in your case you should use an offset of 8 hours (instead of just 1 hour).

And as explained also in that tutorial: "Initially execute the component manually" (from then on every other 8 hours the rule will be executed again).

Option 2: Using modules Rules and Rules Once per Day

There is a fairly new module related to rules, i.e. the "Rules Once per Day" module. Here is how it works (as per the comment in issue 2495775, from the module owner):

  • You specify a trigger hour on the administration settings page for this module.
  • The Rule trigger will then run when cron tasks are first run after the start of that hour. The actual run time will depend on your cron task timings.

The way to understand/read this is like so:

  • The "Event" will only be triggered when a cron job is run.
  • And that event will only be triggered 1 time / day, i.e. "next time cron runs after the trigger hour has passed".

So by creating 3 similar rules, you could have 1 of them run around (say) 6 am, another one around 2 pm and the ast one at 10 pm. Adapt the 6am to any other timestamp you'd want, and do the same with the one from 2 pm and 10 pm

  • 1
    Thanks @Pierre.Vriens. I have implemented 2nd option. Let you know once rule is executed. Thanks for reply. – DRUPWAY Apr 26 '16 at 14:38
  • no luck i have not received any emails. I think i am missing something. – DRUPWAY Apr 28 '16 at 5:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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