Skip to main content

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

- 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 KeyRequired/OptionalData Types and ValuesDescription
sql_statementRequiredStringAny single SQL statement, or a call to a stored procedure, executed when the task runs
warehouseRequiredStringSpecifies the virtual warehouse that is used to execute the task
afterOptionalMap/List of StringSpecifies one or more predecessor task for the current task. When a run of the predecessor task finishes successfully, it triggers this task after a brief lag.
commentOptionalStringSpecifies a comment for the task
deletedOptionalBoolean: True enables deletion prevention, False does nothingSpecifies what objects are allowed to be deleted
enabledOptionalBooleanSpecifies if the task should be started (enabled) after creation or should remain suspended (default)
grantsOptionalMap: See Supported Task Grants to RolesList of Privileges and Roles to which privileges are granted on the current task
manage_modeOptionalString: all (default), none, grantsConfigures what properties to manage for the task.
See Changing Manage Mode before changing the value.
scheduleOptionalStringSpecifies the schedule for periodically running the task. This can be a cron or interval in minutes
session_parametersOptionalMap of StringSpecifies session parameters to set for the session when the task runs. A task supports all session parameters.
user_task_managed_initial_warehouse_sizeOptionalStringSpecifies 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_msOptionalNumberSpecifies the time limit on a single run of the task before it times out (in milliseconds)
whenOptionalStringSpecifies a Boolean SQL expression, multiple conditions joined with AND/OR are supported

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.

after: "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
ALL PRIVILEGES handling

When you define ALL PRIVILEGES in the SOLE configuration file, you grant all the privileges listed above to roles on this object except OWNERSHIP. However, the management of ALL PRIVILEGES in SOLE differs from its handling in Snowflake. See Handling ALL PRIVILEGES in SOLE for more information.

Examples

- task:
name: TASK_1
database: rel(database.PRODUCTS_RECORD)
schema: rel(schema.PRODUCTS)
sql_statement: "<sql_statement>"
warehouse: rel(warehouse.<warehouse_name>)"
comment: "<task_comment>"
after:
- rel(task.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)
- task:
name: TASK_1
database: rel(database.PRODUCTS_RECORD)
schema: rel(schema.PRODUCTS)
sql_statement: "<sql_statement>"
warehouse: rel(warehouse.<warehouse_name>)"
comment: "<task_comment>"
after:
- rel(task.mytask_minute)
- rel(task.mytask_new)
enabled: "true|false"
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)