Trigger object
The Trigger object comes with two sets of methods: CRUD methods and status methods inherited from the VersionedEntity class.
CRUD methods
CRUD methods are used to interact with the entity object in the backend or locally:
save(): Save or update the entity into the backendexport(): Export the entity locally as yaml filerefresh(): Refresh (read) the entity from the backend
save
Save or update the entity into the backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
update
|
bool
|
Flag to indicate update. |
False
|
Returns:
| Type | Description |
|---|---|
ContextEntity
|
Entity saved. |
export
Export object as a YAML file in the context folder.
Returns:
| Type | Description |
|---|---|
str
|
Exported filepath. |
refresh
Refresh object from backend.
Returns:
| Type | Description |
|---|---|
ContextEntity
|
Entity refreshed. |
Trigger Specifications
The trigger object has specific attributes based on its kind:
Base Trigger
All triggers have these base specifications:
template: Configuration template for the run (dict with parameters/inputs, resources, etc.)task: The task to executefunctionorworkflow: The target process to execute (either a function or workflow)
Scheduler Trigger
Additional specifications:
schedule: Quartz cron expression
Lifecycle Trigger
Additional specifications:
key: Entity key to monitor (format:store://<project>/<entity-type>/<entity-kind>/<name>, can include wildcards*)states: List of states of the monitored entity that will trigger execution
For more details about trigger kinds and their specific configurations, see the kinds section.
Creating Triggers from Functions and Workflows
Triggers can be created directly from Function and Workflow objects using their trigger() method. This provides a convenient way to set up triggers for specific functions or workflows.
Example using a Function:
function = project.get_function("my-function")
# Create a scheduler trigger
trigger = function.trigger(
action="job",
kind="scheduler",
name="daily-function-run",
schedule="0 0 * * *" # Run daily at midnight
)
# Create a lifecycle trigger when an artifact is uploaded
trigger = function.trigger(
action="job",
kind="lifecycle",
name="validate-on-upload",
key="store://project/artifact/*",
states=["READY"]
template={"inputs": {"my-param": "{{input.key}}"}},
)
Example using a Workflow:
workflow = project.get_workflow("my-workflow")
# Create a scheduler trigger
trigger = workflow.trigger(
action="pipeline",
kind="scheduler",
name="weekly-workflow-run",
schedule="0 0 * * 0" # Run weekly on Sunday
)
# Create a lifecycle trigger
trigger = workflow.trigger(
action="pipeline",
kind="lifecycle",
name="validation-pipeline-on-upload",
key="store://project/artifact/*",
states=["READY"],
template={"parameters": {"param-name": "{{input.key}}"}},
)