Task
You can provide configuration to Snowflake Object Lifecycle Engine for the following operation with task:
- Manage the lifecycle of new and existing tasks
Usage
note
We have introduced SOLE for Data Products as a new framework for SOLE to help you easily build an ecosystem of data products. Learn more about SOLE for Data Products which is currently available as a private preview.
- Task in Current Configuration
- Task in SOLE for Data Products
databases:
<database-name>:
schemas:
<schema-name>:
tasks:
<task-name>:
<configuration-key>: <value>
- task:
name: <task-name>
<configuration-key>: <value>
database: rel(database.<database-name>)
schema: rel(schema.<schema-name>)
Supported parameters
The engine supports the parameters listed below.
Configuration Key | Required/Optional | Data Types and Values | Description |
---|---|---|---|
sql_statement | Required | String | Any single SQL statement, or a call to a stored procedure, executed when the task runs |
warehouse | Required | String | Specifies the virtual warehouse that is used to execute the task |
after | Optional | String/Object: See here for a definition of after | Specifies the predecessor task for the current task. When a run of the predecessor task finishes successfully, it triggers this task after a brief lag. |
comment | Optional | String | Specifies a comment for the task |
deleted | Optional | Boolean: True enables deletion prevention, False does nothing | Specifies what objects are allowed to be deleted |
enabled | Optional | Boolean | Specifies if the task should be started (enabled) after creation or should remain suspended (default) |
grants | Optional | Map: See Supported Task Grants to Roles | List of Privileges and Roles to which privileges are granted on the current task |
manage_mode | Optional | String: all (default), none , grants | Configures what properties to manage for the task. See Changing Manage Mode before changing the value. |
schedule | Optional | String | Specifies the schedule for periodically running the task. This can be a cron or interval in minutes |
session_parameters | Optional | Map of String | Specifies session parameters to set for the session when the task runs. A task supports all session parameters. |
user_task_managed_initial_warehouse_size | Optional | String | Specifies the size of the compute resources to allocate for the first run of the task, before a task history is available for Snowflake to determine an ideal size. Once a task has successfully completed a few runs, Snowflake ignores this parameter setting. |
user_task_timeout_ms | Optional | Number | Specifies the time limit on a single run of the task before it times out (in milliseconds) |
when | Optional | String | Specifies a Boolean SQL expression, multiple conditions joined with AND/OR are supported |
after
parameter
The after
parameter supports the following parameters if explicitly provided:
Configuration Key | Required/Optional | Data Types and Values | Description |
---|---|---|---|
name | Required | String | Name of the task |
database | Required - if the task is present in another database | String | Name of the database in which the task exists |
schema | Required - if the task is present in another database or another schema | String | Name of the schema in which the task exists |
Users can specify a task name in two ways:
- as the value of the
after
key - in the
name
sub-key if the task is present in another database or another schema
See Database-Level Object Reference section for more information.
- as value
- as sub-key
after: "mytask_minute"
after:
database: "DUMMY_DATABASE"
schema: "PUBLIC"
name: "mytask_minute"
Supported task grants to roles
Following are the privileges you can grant to roles in the task definition:
- ALL PRIVILEGES
- MONITOR
- OPERATE
- OWNERSHIP
Examples
- Task in Current Configuration
- Task in SOLE for Data Products
databases:
PRODUCTS_RECORD:
schemas:
PRODUCTS:
tasks:
TASK_1:
sql_statement: "<sql_statement>"
warehouse: "<warehouse_name>"
comment: "<task_comment>"
after:
database: "DUMMY_DATABASE"
schema: "PUBLIC"
name: "mytask_minute"
enabled: "true|false"
schedule: "10 MINUTES"
session_parameters:
timestamp_output_format: "DD-MM-YYYY HH24:MI:SS.FF3 TZHTZM"
user_task_timeout_ms: 10000
when: "SYSTEM$STREAM_HAS_DATA('MYSTREAM')"
grants:
MONITOR:
- ANALYST
- task:
name: TASK_1
schema: rel(schema.PRODUCTS)
sql_statement: "<sql_statement>"
warehouse: rel(warehouse.<warehouse_name>)"
comment: "<task_comment>"
after:
database: "DUMMY_DATABASE"
schema: "PUBLIC"
name: "mytask_minute"
enabled: "true|false"
schedule: "10 MINUTES"
session_parameters:
timestamp_output_format: "DD-MM-YYYY HH24:MI:SS.FF3 TZHTZM"
user_task_timeout_ms: 10000
when: "SYSTEM$STREAM_HAS_DATA('MYSTREAM')"
grants:
MONITOR:
- rel(role.ANALYST)