Skip to 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>)
databases:
  <database-name>:
    schemas:
      <schema-name>:
        tasks:
          <task-name>:
            <configuration-key>: <value>

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 Map/List of String Specifies 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.
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
depends_on Optional List of String: See Object Dependencies for a definition of depends_on List of SOLE-managed objects that this task depends on. Objects defined in the list will be added to the generated HCL dependencies list to ensure proper creation order.
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 Map of 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.
target_completion_interval Optional Map of Number Specifies the target completion interval for the task. Accepts minutes, hours, and seconds as keys with numeric values.
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

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"
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

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:
      MINUTES: 10
    session_parameters:
      timestamp_output_format: "DD-MM-YYYY HH24:MI:SS.FF3 TZHTZM"
    target_completion_interval:
      minutes: 6
    user_task_timeout_ms: 10000
    when: "SYSTEM$STREAM_HAS_DATA('MYSTREAM')"
    grants:
      MONITOR:
        - rel(role.ANALYST)
databases:
  PRODUCTS_RECORD:
    schemas:
      PRODUCTS:
        tasks:
          TASK_1:
            sql_statement: "<sql_statement>"
            warehouse: "<warehouse_name>"
            comment: "<task_comment>"
            after:
              - mytask_minute
            enabled: "true|false"
            schedule:
              using_cron: "*/10 * * * *"
            session_parameters:
              timestamp_output_format: "DD-MM-YYYY HH24:MI:SS.FF3 TZHTZM"
            target_completion_interval:
              minutes: 6
            user_task_timeout_ms: 10000
            when: "SYSTEM$STREAM_HAS_DATA('MYSTREAM')"
            grants:
              MONITOR:
                - 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"
    target_completion_interval:
      minutes: 6
    user_task_timeout_ms: 10000
    when: "SYSTEM$STREAM_HAS_DATA('MYSTREAM')"
    grants:
      MONITOR:
        - rel(role.ANALYST)
databases:
  PRODUCTS_RECORD:
    schemas:
      PRODUCTS:
        tasks:
          TASK_1:
            sql_statement: "<sql_statement>"
            warehouse: "<warehouse_name>"
            comment: "<task_comment>"
            after:
              - mytask_minute
              - mytask_new
            enabled: "true|false"
            session_parameters:
              timestamp_output_format: "DD-MM-YYYY HH24:MI:SS.FF3 TZHTZM"
            target_completion_interval:
              minutes: 6
            user_task_timeout_ms: 10000
            when: "SYSTEM$STREAM_HAS_DATA('MYSTREAM')"
            grants:
              MONITOR:
                - ANALYST