snowflake.core.task.Task

class snowflake.core.task.Task(name: str, definition: str | StoredProcedureCall, *, warehouse: str | None = None, user_task_managed_initial_warehouse_size: str | None = None, suspend_task_after_num_failures: int | None = None, user_task_timeout_ms: int | None = None, schedule: Cron | timedelta | None = None, allow_overlapping_execution: bool | None = None, error_integration: str | None = None, comment: str | None = None, predecessors: List[str] | None = None, condition: str | None = None, config: Dict[str, Any] | None = None, session_parameters: Dict[str, Any] | None = None, id: str | None = None, created_on: datetime | None = None, last_committed_on: datetime | None = None, last_suspended_on: datetime | None = None, state: str | None = None, database_name: str | None = None, schema_name: str | None = None, owner: str | None = None, owner_role_type: str | None = None)

Bases: object

Represents a Snowflake Task.

Attributes

sql_definition

The definition of the task in SQL text.

It’s a readonly property. To set the definition of the Task, use definition.

If definition is a StoredProcedureCall, the SQL that calls the stored procedure, or the

anonymous stored procedure definition will be returned.

name: str

Name of the task.

definition: str | StoredProcedureCall

Definition of the task.

Any one of the following:
  • A SQL Statement. It can be a single SQL statement, or a procedural logic using Snowflake Scripting.

  • A StoredProcedureCall instance. This provides a Pythonic way to call an existing stored procedure, or use a Snowflake annonymous stored procedure in Python.

warehouse

The virtual warehouse that provides compute resources for task runs. Omit this parameter if you want to use the serverless Snowflake-managed compute resources for runs of this task.

user_task_managed_initial_warehouse_size

The size of the compute resources to provision 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. Note that if the task history is unavailable for a given task, the compute resources revert to this initial size.

A warehouse size is the same as in creating a virtual warehous.

If warehouse is specified for this task, then setting this parameter produces an error.

schedule

The schedule for periodically running the task. The minimum schedule is 1 minute.

suspend_task_after_num_failures

Specifies the number of consecutive failed task runs after which the current task is suspended automatically. Failed task runs include runs in which task body either produces a user error or times out. Task runs that are skipped, canceled, or that fail due to a system error are considered indeterminate and are not included in the count of failed task runs.

Set the parameter on a standalone task or the root task in a DAG. When the parameter is set to a value greater than 0, the following behavior applies to runs of the standalone task or DAG:

Standalone tasks are automatically suspended after the specified number of consecutive task runs either fail or time out.

The root task is automatically suspended after the run of any single task in a DAG fails or times out the specified number of times in consecutive runs.

user_task_timeout_ms

Specifies the time limit on a single run of the task before it times out (in milliseconds).

allow_overlapping_execution

Whether to allow multiple instances of the DAG to run concurrently.

error_integration

Specifies the name of the notification integration used to communicate with Amazon SNS, MS Azure Event Grid, or Google Pub/Sub.

For more information, refer to Enabling Error Notifications for Tasks.

Required only when configuring a task to send error notifications using Amazon Simple Notification Service (SNS), Microsoft Azure Event Grid, or Google Pub/Sub.

comment

Specifies a comment for the task.

predecessors

Specifies one or more predecessor tasks for the current task. Use this option to create a DAG of tasks or add this task to an existing DAG.

A DAG is a series of tasks that starts with a scheduled root task and is linked together by dependencies.

condition: str | None

Specifies a Boolean SQL expression; multiple conditions joined with AND/OR are supported. When a task is triggered (based on its SCHEDULE or AFTER setting), it validates the conditions of the expression to determine whether to execute. If the conditions of the expression are not met, then the task skips the current run. Any tasks that identify this task as a predecessor also do not run.

SYSTEM$STREAM_HAS_DATA is the only function supported for evaluation in the SQL expression. This function indicates whether a specified stream contains change tracking data.

config

Set the configuration for the task. It can only be set on a root task then it applies to all tasks in the DAG. The parameter can be set on standalone tasks but does not affect the task behavior. Snowflake ensures only one instance of a standalone task is running at a given time.

session_parameters

Set the session parameters for the task at runtime.

created_on

Date and time when the task was created.

last_committed_on

Timestamp when a version of the task was last set. If no version has been set (i.e. if the task has not been resumed or manually executed after it was created), the value is NULL.

last_suspended_on

Timestamp when the task was last suspended. If the task has not been suspended yet, the value is NULL.

state

“started” or “suspended” based on the current state of the task.

database_name

Database in which the task is stored.

schema_name

Schema in which the task is stored.

owner

Role that owns the task (i.e. has the OWNERSHIP privilege on the task)

owner_role_type

The type of role that owns the object, either ROLE or DATABASE_ROLE. Note that Snowflake returns NULL if you delete the object because there is no owner role for a deleted object.

Methods

__init__(name: str, definition: str | StoredProcedureCall, *, warehouse: str | None = None, user_task_managed_initial_warehouse_size: str | None = None, suspend_task_after_num_failures: int | None = None, user_task_timeout_ms: int | None = None, schedule: Cron | timedelta | None = None, allow_overlapping_execution: bool | None = None, error_integration: str | None = None, comment: str | None = None, predecessors: List[str] | None = None, condition: str | None = None, config: Dict[str, Any] | None = None, session_parameters: Dict[str, Any] | None = None, id: str | None = None, created_on: datetime | None = None, last_committed_on: datetime | None = None, last_suspended_on: datetime | None = None, state: str | None = None, database_name: str | None = None, schema_name: str | None = None, owner: str | None = None, owner_role_type: str | None = None) None
语言: 中文