snowflake.core.task.TaskResourceΒΆ

class snowflake.core.task.TaskResource(name: str, collection: TaskCollection)ΒΆ

Bases: SchemaObjectReferenceMixin[TaskCollection]

Represents a reference to a Snowflake Task resource.

Attributes

databaseΒΆ
fully_qualified_nameΒΆ
rootΒΆ

Methods

create_or_alter(task: Task) β†’ NoneΒΆ

Create a task in Snowflake or alter one if it already exists.

The Snowflake task’s properties will be updated to the properties of the input task if the task already exists. Note that the full picture of a task is expected. If a property isn’t set a value in the input task, the property will be set to NULL in Snowflake too because it’s regarded as the expected value.

Parameters:

task (Task) – An instance of Task.

Examples

>>> task_parameters = Task(
...     name="your-task-name",
...     definition="select 1"
... )
Copy

# Using a TaskCollection to create a reference to task in Snowflake server:

>>> root.warehouses["your-task-name"].create_or_alter(task_parameters)
Copy
create_or_update(task: Task) β†’ NoneΒΆ

The create_or_update method is deprecated; use create_or_alter instead.

delete() β†’ NoneΒΆ

Delete this task.The delete method is deprecated; use drop instead.

drop(if_exists: bool | None = None) β†’ NoneΒΆ

Drop this task.

Parameters:

if_exists (bool, optional) – Check the existence of this task before dropping it. Default is None, which is equivalent to False.

Examples

Deleting a task using its reference:

>>> task_reference.drop()
Copy
execute(*, retry_last: bool = False) β†’ NoneΒΆ

Execute the task immediately without waiting for the schedule.

Parameters:

retry_last (bool, optional) – Re-execute the last failed task of the DAG. Default is False.

Examples

Execute a task using its reference:

>>> task_reference.execute()
Copy
fetch() β†’ TaskΒΆ

Fetch the task resource.

Examples

Fetching a task using its reference:

>>> task = task_reference.fetch()
Copy

Accessing information of the task with task instance:

>>> print(task.name, task.comment)
Copy
fetch_task_dependents() β†’ List[Task]ΒΆ

Return the list of child tasks that use this task as the root in a DAG.

Examples

Fetching the child tasks of a task using its reference:

>>> child_tasks = task_reference.fetch_task_dependents()
Copy
get_complete_graphs(*, error_only: bool = True) β†’ Iterable[TaskRun]ΒΆ

Return the status of a completed graph run.

It returns details for runs that executed successfully, failed, or were cancelled in the past 60 minutes.

To retrieve the details for graph runs that are currently executing, or are next scheduled to run within the next 8 days, use get_current_graphs().

Parameters:

error_only (bool, optional) – Return only the graph runs that have failed. Default is True.

Examples

Getting the completed graph runs of a task using its reference:

>>> completed_graphs = task_reference.get_complete_graphs()
Copy
get_current_graphs() β†’ Iterable[TaskRun]ΒΆ

Return the status of a graph run that is currently scheduled or is executing.

It returns details for graph runs that are currently executing or are next scheduled to run within the next 8 days. To retrieve the details for graph runs that have completed in the past 60 minutes, use get_complete_graphs().

Examples

Getting the current graph runs of a task using its reference:

>>> current_graphs = task_reference.get_current_graphs()
Copy
resume() β†’ NoneΒΆ

Resume the task then it will run on the schedule.

Examples

Resume a task using its reference:

>>> task_reference.resume()
Copy
suspend() β†’ NoneΒΆ

Suspend the task so it won’t run again on the schedule.

Examples

Suspend a task using its reference:

>>> task_reference.suspend()
Copy