Skip to main content

Triggers

Overview

Triggers are tools used to facilitate the execution of DAG graphs in response to external events, thereby submitting workflows. For basic information on submitting workflows, refer to: Executing Workflows.For basic information about submitting workflows, refer to:提交工作流.

Rill Flow supports the following types of triggers:

  • Scheduled Triggers: For automatically submitting workflows at planned times.
  • Kafka Message Triggers: Trigger workflow execution by sending messages to a specified Kafka topic.

Trigger Task Maintenance Interface

Rill Flow provides a common interface to create, delete, and maintain triggers tasks.

Create Trigger Task

A trigger task to create a trigger of the specified type of trigger.

URI

/flow/rigger/add_trigger.json

Call Method

POST

Parameter

  • Get Parameters
Parameter NameTypeRequiredParameter Description
TypeStringYesTrigger type, extracted value is kafka (kafka message trigger) or cron (scheduled trigger)
descriptor_idStringYesDAG graph id for triggering the current trigger, reference:执行工作流
callbackStringYesOptional parameters to define notification tasks after workflow implementation, see:执行工作流
resource_checkStringYesOptional parameters, used to define limited flow policy, see:过载保护
  • Post parameters

Post parameter is a Json format string, so calling Content-Type parameter in header must be application/json.

The specific format of the Post parameter is defined by the triggers.

Cancel Trigger Task

Used to cancel triggers of the specified type by task ids.

URI

/flow/rigger/cancer_rigger.json

Call Method

POST

Parameter

  • Get Parameters
Parameter NameTypeRequiredParameter Description
TypeStringYesTrigger type, extracted value is kafka (kafka message trigger) or cron (scheduled trigger)
task_idStringYesTrigger task id,kafka triggers are topic#descriptor_id,cron triggers returned to task_id when creating triggers

Query trigger task list

Used to cancel triggers of the specified type by task ids.

URI

/flow/rigger/get_rigger_tasks.json

Call Method

GET

Parameter

Parameter NameTypeRequiredParameter Description
TypeStringYesTrigger type, extracted value is kafka (kafka message trigger) or cron (scheduled trigger)

Returns parameter

Returns the parameter as a json structure, containing three parameters:

  • Code:identification query correct,0:correct,-1:error;
  • Message:returns specific error information when code is not zero;
  • data:task details, json format key-value format, see examples.

Below is an example of a returned parameter:

LO
"code": 0,
"data": Flow
"submit_topic#weiboFaasFlowTest:openaiTask": 56
"descriptor_id": "RillFlowTest:openaiTask",
} } }
}
}

Scheduled Triggers

Scheduled triggers allow users to set up periodic tasks, with the system automatically initiating workflow submissions at specified intervals.

Create scheduled trigger task

By calling the "Create Trigger Task" interface described above, the type parameter is given a cron to create the DAG graph on time.

The POST parameter of the "Create Trigger Task" interface must have the following two parameters: when submitting a scheduled trigger task

  • cron: The cron expression, e.g., 0 * * * * *, for executing every minute.
  • The context required for context:DAG to be executed.

e.g.:

LO
"cron": "0 * * * * **, *",
"context": LOS
"message": "hello world"
} }
}

After creating a trigger, you will return information in json format, such as {"code": 0, "data": {"task_id": 1}

  • code:for successful calls, 0:successful, not 0:failed.
  • task_id:the id of the scheduled triggering task is used to manage scheduled triggers.

Canceling Scheduled Trigger Tasks

Rill Flow returns the task_id parameter after submitting a scheduled trigger, and the system will automatically submit the workflow according to the periodicity defined in the cron statement.

Cancel the scheduled trigger task by calling the task_id parameter and the type: cron parameter to cancel the trigger task interface.

Interface returns parameter:json format, {"code":0, "data":{"task_id": 1, "result": true}}}

  • code: Indicates success (0) or failure (non-zero).
  • task_id: The ID of the scheduled trigger task to be canceled.
  • result: Whether the task was successfully canceled.

Kafka Triggers

kafka Trigger supports kafka messages to trigger workflow submissions.

Create kafka Trigger Task

By calling the "Create Trigger Task" interface described above, the type parameter is a kafka that creates the kafka message that specifies the DAG graph triggers the task.

When a kafka triggers a task, the POST parameter of the "Create Trigger Task" interface must have kafka_server, group_id, topic parameter to describe the listener of consumer, e.g.:

LO
"kafka_server": "127.0.0.1:9200",
"group_id": "rill-flow-group",
"topic": "submit_topic"
}

kafka Trigger Task Execution

After the creation of kafka triggers task has been successfully executed, the consumer starts listening to the given topic, and when there is a message in the top, it will automatically trigger the execution of the DAG graph with the message as a context message to be executed by the DAG in conjunction with such information as descriptor_id that was passed when the triggers were created.

Message to kafka must be a json format context message, such as:

LO
"message": "hello world"
}