Skip to main content

tasks

Creates, updates, deletes, gets or lists a tasks resource.

Overview

Nametasks
TypeResource
Idsnowflake.pipelines.tasks

Fields

The following fields are returned by SELECT queries:

successful

NameDatatypeDescription
idstringAn ID for the current task.
namestringString that specifies the identifier (i.e. name) for the task. (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$, example: TEST_NAME)
database_namestringThe name of the parent database for the task.
schema_namestringThe name of the parent schema for the task.
allow_overlapping_executionbooleanSpecifies whether to allow multiple instances of the DAG to run concurrently.
commentstringSpecifies a comment for the task.
conditionstringSpecifies a Boolean SQL expression condition; multiple conditions joined with AND/OR are supported
configobjectTask Config
created_onstring (date-time)The time the task was created on.
definitionstringThe SQL definition for the task. Any one of single SQL statement, call to stored procedure, or procedural logic using Snowflake scripting.
error_integrationstringSpecifies the name of the notification integration used to communicate with Amazon SNS, MS Azure Event Grid, or Google Pub/Sub.
finalizestringSpecifies the name of the root task that the finalizer task is associated with.
last_committed_onstring (date-time)The time the task was last committed on.
last_suspended_onstring (date-time)The time the task was last suspended on.
ownerstringThe role that owns the task.
owner_role_typestringThe role type of the task owner.
predecessorsarraySpecifies one or more predecessor tasks for the current task
scheduleobjectSpecifies the schedule for periodically running the task.
serverless_task_max_statement_sizestringSpecifies the maximum allowed warehouse size for the serverless task. Minimum XSMALL, Maximum XXLARGE. This parameter only applies to serverless tasks.
serverless_task_min_statement_sizestringSpecifies the minimum allowed warehouse size for the serverless task. Minimum XSMALL, Maximum XXLARGE. This parameter only applies to serverless tasks.
session_parametersobjectSession Parameters for the task at runtime.
statestringThe state of the task. Must be one of started or suspended. (started, suspended)
suspend_task_after_num_failuresintegerSpecifies the number of consecutive failed task runs after which the current task is suspended automatically.
target_completion_intervalobjectSpecifies the desired task completion time. This parameter only applies to serverless tasks.
task_auto_retry_attemptsintegerRoot task settable only. Specifies the number of automatic task graph retry attempts. Valid range is 0 to 30. When not specified, no retry would happen.
task_relationsstringDisplays the relationship between the root task and its corresponding finalizer tasks.
user_task_managed_initial_warehouse_sizestringSpecifies the size of the compute resources to provision for the first run of the task. This parameter only applies to serverless tasks.
user_task_timeout_msintegerSpecifies the time limit on a single run of the task before it times out (in milliseconds).
warehousestringSpecifies the virtual warehouse that provides compute resources for task runs. Omit this parameter to use serverless compute resources for runs of this task. (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$, example: TEST_NAME)

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectdatabase_name, schema_name, name, endpointFetch a task using the describe command output.
listselectdatabase_name, schema_name, endpointrootOnly, like, startsWith, showLimit, fromNameLists tasks under the database and schema, with show options as query parameters.
createinsertdatabase_name, schema_name, endpoint, name, definitioncreateModeCreate a task, with standard create modifiers as query parameters. See the Task component definition for what is required to be provided in the request body.
create_or_alterreplacedatabase_name, schema_name, task_name, endpoint, name, definitionCreate a (or alter an existing) task. Even if the operation is just an alter, the full property set must be provided.
deletedeletedatabase_name, schema_name, name, endpointifExistsDelete a task with the task name. If ifExists is used, the operation will succeed even if the object does not exist. Otherwise, there will be a failure if the drop is unsuccessful.
executeexecdatabase_name, schema_name, name, endpointasyncExec, retryLastExecute a task -- this is equivalent to EXECUTE IMMEDIATE.
resumeexecdatabase_name, schema_name, name, endpointResumes a suspended task object. This is equivalento an ALTER TASK ... RESUME.
suspendexecdatabase_name, schema_name, name, endpointSuspends a running task. This is equivalent to an ALTER TASK ... SUSPEND.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
database_namestringIdentifier (i.e. name) for the database to which the resource belongs. You can use the /api/v2/databases GET request to get a list of available databases.
endpointstringOrganization and account identifier (orgname-accountname) (default: orgname-accountname)
namestringIdentifier (i.e. name) for the resource.
schema_namestringIdentifier (i.e. name) for the schema to which the resource belongs. You can use the /api/v2/databases/{database}/schemas GET request to get a list of available schemas for the specified database.
task_namestringIdentifier (i.e. name) for the resource.
asyncExecbooleanAsynchronous execution enable/disable. Default is disable.
createModestringParameter allowing support for different modes of resource creation. Possible values include: - errorIfExists: Throws an error if you try to create a resource that already exists. - orReplace: Automatically replaces the existing resource with the current one. - ifNotExists: Creates a new resource when an alter is requested for a non-existent resource.
fromNamestringParameter to enable fetching rows only following the first row whose object name matches the specified string. Case-sensitive and does not have to be the full name.
ifExistsbooleanParameter that specifies how to handle the request for a resource that does not exist: - true: The endpoint does not throw an error if the resource does not exist. It returns a 200 success response, but does not take any action on the resource. - false: The endpoint throws an error if the resource doesn't exist.
likestringParameter to filter the command output by resource name. Uses case-insensitive pattern matching, with support for SQL wildcard characters.
retryLastbooleanRetry the last failed run of the DAG.
rootOnlybooleanParameter to filter the command output to return only root resources (resources with no predecessors).
showLimitintegerParameter to limit the maximum number of rows returned by a command.
startsWithstringParameter to filter the command output based on the string of characters that appear at the beginning of the object name. Uses case-sensitive pattern matching.

SELECT examples

Fetch a task using the describe command output.

SELECT
id,
name,
database_name,
schema_name,
allow_overlapping_execution,
comment,
condition,
config,
created_on,
definition,
error_integration,
finalize,
last_committed_on,
last_suspended_on,
owner,
owner_role_type,
predecessors,
schedule,
serverless_task_max_statement_size,
serverless_task_min_statement_size,
session_parameters,
state,
suspend_task_after_num_failures,
target_completion_interval,
task_auto_retry_attempts,
task_relations,
user_task_managed_initial_warehouse_size,
user_task_timeout_ms,
warehouse
FROM snowflake.pipelines.tasks
WHERE database_name = '{{ database_name }}' -- required
AND schema_name = '{{ schema_name }}' -- required
AND name = '{{ name }}' -- required
AND endpoint = '{{ endpoint }}' -- required
;

INSERT examples

Create a task, with standard create modifiers as query parameters. See the Task component definition for what is required to be provided in the request body.

INSERT INTO snowflake.pipelines.tasks (
name,
warehouse,
schedule,
comment,
finalize,
task_auto_retry_attempts,
config,
session_parameters,
definition,
predecessors,
user_task_managed_initial_warehouse_size,
target_completion_interval,
serverless_task_min_statement_size,
serverless_task_max_statement_size,
user_task_timeout_ms,
suspend_task_after_num_failures,
condition,
allow_overlapping_execution,
error_integration,
database_name,
schema_name,
endpoint,
createMode
)
SELECT
'{{ name }}' /* required */,
'{{ warehouse }}',
'{{ schedule }}',
'{{ comment }}',
'{{ finalize }}',
{{ task_auto_retry_attempts }},
'{{ config }}',
'{{ session_parameters }}',
'{{ definition }}' /* required */,
'{{ predecessors }}',
'{{ user_task_managed_initial_warehouse_size }}',
'{{ target_completion_interval }}',
'{{ serverless_task_min_statement_size }}',
'{{ serverless_task_max_statement_size }}',
{{ user_task_timeout_ms }},
{{ suspend_task_after_num_failures }},
'{{ condition }}',
{{ allow_overlapping_execution }},
'{{ error_integration }}',
'{{ database_name }}',
'{{ schema_name }}',
'{{ endpoint }}',
'{{ createMode }}'
RETURNING
status
;

REPLACE examples

Create a (or alter an existing) task. Even if the operation is just an alter, the full property set must be provided.

REPLACE snowflake.pipelines.tasks
SET
name = '{{ name }}',
warehouse = '{{ warehouse }}',
schedule = '{{ schedule }}',
comment = '{{ comment }}',
finalize = '{{ finalize }}',
task_auto_retry_attempts = {{ task_auto_retry_attempts }},
config = '{{ config }}',
session_parameters = '{{ session_parameters }}',
definition = '{{ definition }}',
predecessors = '{{ predecessors }}',
user_task_managed_initial_warehouse_size = '{{ user_task_managed_initial_warehouse_size }}',
target_completion_interval = '{{ target_completion_interval }}',
serverless_task_min_statement_size = '{{ serverless_task_min_statement_size }}',
serverless_task_max_statement_size = '{{ serverless_task_max_statement_size }}',
user_task_timeout_ms = {{ user_task_timeout_ms }},
suspend_task_after_num_failures = {{ suspend_task_after_num_failures }},
condition = '{{ condition }}',
allow_overlapping_execution = {{ allow_overlapping_execution }},
error_integration = '{{ error_integration }}'
WHERE
database_name = '{{ database_name }}' --required
AND schema_name = '{{ schema_name }}' --required
AND task_name = '{{ task_name }}' --required
AND endpoint = '{{ endpoint }}' --required
AND name = '{{ name }}' --required
AND definition = '{{ definition }}' --required
RETURNING
status;

DELETE examples

Delete a task with the task name. If ifExists is used, the operation will succeed even if the object does not exist. Otherwise, there will be a failure if the drop is unsuccessful.

DELETE FROM snowflake.pipelines.tasks
WHERE database_name = '{{ database_name }}' --required
AND schema_name = '{{ schema_name }}' --required
AND name = '{{ name }}' --required
AND endpoint = '{{ endpoint }}' --required
AND ifExists = '{{ ifExists }}'
;

Lifecycle Methods

Execute a task -- this is equivalent to EXECUTE IMMEDIATE.

EXEC snowflake.pipelines.tasks.execute
@database_name='{{ database_name }}' --required,
@schema_name='{{ schema_name }}' --required,
@name='{{ name }}' --required,
@endpoint='{{ endpoint }}' --required,
@asyncExec={{ asyncExec }},
@retryLast={{ retryLast }}
;