Community Conundrum 25:Feature Visualization is now live! Read More

Scenario Custom Trigger Tips

Level 4
Scenario Custom Trigger Tips

I have been working on writing a custom Python trigger script that enables flexible time-based scheduling. For example, running a scenario at multiple times during business hours on weekdays and then on a different schedule on the weekend.

One could do some versions of such a schedule with a bunch of built-in time-based triggers. In my case it would have required close to 500 triggers so wasn't feasible.

In the process of writing this, I learned a few things about custom Python triggers. Thought I would share a few notes in the reply below.

2 Replies
Level 4
  • The backend.log file (read via Admin > Maintenance) is the place to look for trigger logging (Clement pointed me to this).
  • Triggers have two methods besides "fire()", "get_trigger()" and "get_trigger_state()"

In my testing, get_trigger() returned the following dict (which matches pretty clearly to the trigger parameters specified in the UI):

{u'name': u'Trigger Name',
u'graceDelaySettings': {u'delay': 0, u'checkAgainAfterGraceDelay': False},
u'delay': 30,
u'params': {u'code': 'your script here', u'envSelection': {u'envMode': u'INHERIT'}},
u'active': True,
u'type': u'custom_python',
u'id': u'Ju7jasV7'}

and get_trigger_state() returned None.

  • The "Run every (seconds)" parameter (same as the "delay" item in the above dict) specifies a timer that starts after the trigger script completes. In other words, however long the trigger script takes isn't counted as part of the time (particuarly relevant for me as my script sometimes has a delay before firing).
  • You can pass a dict of values in the "fire()" method that you can retrieve in a Scenario step via Scenario().get_trigger_params(). This might be helpful if you want a step to have information about the triggering event. For example,{'key1':'val1', 'key2':'val2').
Community Manager
Community Manager

Awesome! Thanks for sharing your knowledge, Marlan!

Lisa, Community Programs Manager at Dataiku

Don't forget to mark as "Accepted Solution" when someone provides the correct answer to your question 😉
0 Kudos
Labels (2)