I can't seem to make any trigger work with conditions.

See http://pastebin.com/A0VXQ4DJ for some tested rules.

My ultimate goal is to send an email when a backup fails, but I would settle for sending an email when any task fails.

Comments

gboudrias’s picture

After some tests, I think the conditions are not evaluated at the right moment, as the task_status seems to always be -1 (which I believe is processing).

gboudrias’s picture

I'm pretty sure the problem is that we're implementing function drush_aegir_rules_pre_hosting_task(), which (as far as I can remember), triggers right after the task has been set to "processing.

What we want in most instances would be drush_aegir_rules_post_hosting_task(), but I can't seem to make that work. I'm not sure if it's not implemented or if I'm missing something. At worst we could resort to individual triggers: http://api.aegirproject.org/api/aegir/hosting2!hosting.api.php/function/...

gboudrias’s picture

Ok I had a non-functional site, drush_aegir_rules_post_hosting_task() does work as expected.

However the status of the task isn't set until after that hook is processed, in hosting_task_drush_init().

helmo’s picture

Title: Task conditions don't appear to work » Pre task event alreasy has processing status

This relates a bit to #2772635: Hook into task failure

We might also have to switch from the pre_ hook to something that is run just before all the others pre hooks. I think the drush_hosting_task_validate() might be the place to start invoking a new hook for this.

helmo’s picture

Title: Pre task event alreasy has processing status » Pre task event already has processing status
Version: 6.x-1.x-dev » 7.x-3.x-dev
helmo’s picture

Priority: Major » Normal
Status: Active » Closed (works as designed)

For the initial goal from #0 "send an email when a backup fails" you need a post event, which now works as per the example in the README file.

Looking at the task log below the processing state is started from the validate hook. So I'm not dure we have any earlier hooks.

Task starts processing: Verify Platform: drupal-7.x
Returned from hook drush_hosting_task_validate	
Calling hook drush_aegir_rules_pre_hosting_task	
Returned from hook drush_aegir_rules_pre_hosting_task

I'm closing for now as the start may say processing but the event is fired before the work is actually started... please re-open if you find a usecase or hook that affects this.