Trigger

A trigger defines how and when pipelines are executed automatically.

Trigger defines rules to executes automatically pipelines, ensuring that processes run efficiently without manual intervention.

Trigger can be created from User Interface in Design section or using the API. They play a crucial role in automating workflows by specifying conditions under which pipelines are initiated.
Note that once triggers are set to execute a pipeline automatically, they cannot be modified using the API within that context.

Triggers can be based on various conditions such as time intervals and delays and custom properties, providing flexibility and control over the execution of pipelines. This automation capability enhances productivity and ensures timely data processing and analysis.

Here is an example creating a template:



Interval & Delay

Triggers support scheduled executions, a trigger will execute a pipeline at specific intervals of time.

Each interval are normally aligned to 0 days 0 hours 0 minutes 0 seconds and 0 milliseconds. An interval of 10 minutes for example, will trigger at 0h10, 0h20, 0h30 etc …

You can add a delay to it in milliseconds, e.g. 300000 ms or 5 minutes will triggers at 0h05, 0h15, 0h25, etc …

# partial example to create a trigger
trigger = wizata_dsapi.Trigger()
trigger.interval = 600000
trigger.delay = 300000
# other fields
wizata_dapi.api().create(trigger)

Triggers are made so timestamps are perfectly aligned regardless when the trigger is created or started. Pipeline Execution created from the trigger will have a sharp queued date. The queued date is by default used as now timestamp defining query relatives date.

When creating a trigger using the platform interface, there is also an option to add the previously explained delay/interval.

Figure 1. Adding an interval and delay to trigger

Figure 1. Adding an interval and delay to trigger

Template

Triggers must reference the pipeline to execute automatically, if your pipeline is templated you should also specify it on your triggers. That way it is set on generated executions and also ease the selection of twins.

# example to update the trigger template and pipeline
trigger = wizata_dsapi.api().get(id=uuid.UUID("your-id") , entity="triggers")
trigger.pipeline_id = uuid.UUID("your-pipeline-id")
trigger.template_id = uuid.UUID("your-template-id")
wizata_dsapi.api().update(trigger)

Properties

You can define fixed properties to pass to your Pipeline execution through the Triggers properties field.

trigger.properties = {
    "key" : "value"
}

This JSON dictionary can also be passed inside the Properties field inside the trigger creation using the user interface.

Figure 2. Adding a property JSON field inside a trigger.

Figure 2. Adding a property JSON field inside a trigger.

Using queued or started date time

A pipeline within its context defines the 'now' date to be used : e.g. for a relative query (now -> now-10m). You can specify which date the pipeline should use as a referenced by setting a property 'now' to either:

  • 'queued' - (default) the pipeline will use as now the moment it was pushed to the queue waiting for its execution. Using queued date time is recommended when keeping timestamp consistency is required (e.g. to sharp 00h0Xm00s.000 timestamp) as the queued date time can be controlled and always correspond to a sharp value calculated from interval and delay. Also it ensures regardless on execution time, it use the time range you specified within the trigger parameters.
  • 'started' - the pipeline will use as now the moment it was started on the pipeline engine regardless on when it was triggered or queued.
{
  "now":"started"
}

📘

Remember if your pipeline is writing data it will use the timestamp resulting of your query by default.

Twins

You might specify, while using a templated pipeline, all registered twins on which you would like to execute the triggers. At each interval elapsing, the triggering service will create an execution for each twin properly registered on the pipeline.

trigger.twin_ids = [
    "your-twin-id1" , "your-twin-id2"
]

Sample

Here is a complete example of a Trigger creation using the Wizata DSAPI Python toolkit:

trigger = wizata_dsapi.Trigger()
trigger.interval = 600000
trigger.delay = 300000
trigger.pipeline_id = '12bf7b2f-e791-4d98-86c6-19ada0274012'
trigger.template_id = '1da299e3-8bfe-4688-9779-bd43ea28060b'
trigger.properties = {
    "from": "now-30d",
    "to": "now"
}
trigger.twin_ids = [
    "48d07d92-df8c-49fb-9df7-ca6621f35c8c" , "cf3dd6b7-cce2-4b8b-b1bd-169552362dfa"
]
wizata_dapi.api().create(trigger)

We can also recreate the same example using the user interface platform: