Adding a Time Trigger to a Lattice#
This example illustrates how to use a covalent.trigger.TimeTrigger to trigger workflow dispatches automatically at a specified interval.
Prerequisites#
Import Covalent and the trigger.
[1]:
import covalent as ct
from covalent.triggers import TimeTrigger
Procedure#
Create a
TimeTrigger
object that performs a trigger action every 5 seconds.
[2]:
time_trigger = TimeTrigger(time_gap=5)
Create a workflow:
[3]:
@ct.lattice
@ct.electron
def my_workflow():
return 42
Dispatch
my_workflow
, disabling its first execution using thedisable_run
parameter inct.dispatch
.
[4]:
dispatch_id = ct.dispatch(my_workflow)()
print(dispatch_id)
44f56fcf-96dc-4089-84d4-069fd13e3e58
Attach the trigger to the
dispatch_id
and register it with the trigger server.
[5]:
time_trigger.lattice_dispatch_id = dispatch_id
time_trigger.register()
Monitor the Covalent UI. Watch the Dashboard for new dispatches of
my_workflow
.In the Covalent UI, observe that a new
my_workflow
is dispatched every five seconds.To disable triggers on the dispatch, use the
ct.stop_triggers
function.
[6]:
ct.stop_triggers(dispatch_id)
[2023-09-25 08:51:25,893] [DEBUG] local.py: Line 334 in stop_triggers: Triggers for following dispatch_ids have stopped observing:
[2023-09-25 08:51:25,894] [DEBUG] local.py: Line 336 in stop_triggers: 44f56fcf-96dc-4089-84d4-069fd13e3e58
Note that the stop_triggers
function disables all triggers attached to the specified dispatch.
See Also#
Adding a Directory Trigger to a Lattice