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ΒΆ
The DatabaseResource this reference belongs to.
- fully_qualified_nameΒΆ
Return the fully qualified name of the object this reference points to.
- rootΒΆ
The Root object this reference belongs to.
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
taskif the task already exists. Note that the full picture of a task is expected. If a property isnβt set a value in the inputtask, the property will be set toNULLin Snowflake too because itβs regarded as the expected value.Examples
>>> task_parameters = Task(name="your-task-name", definition="select 1")
# Using a
TaskCollectionto create a reference to task in Snowflake server:>>> root.warehouses["your-task-name"].create_or_alter(task_parameters)
- create_or_alter_async(task: Task) PollingOperation[None]ΒΆ
An asynchronous version of
create_or_alter().Refer to
PollingOperationfor more information on asynchronous execution and the return type.
- create_or_update(task: Task) NoneΒΆ
The
create_or_update()method is deprecated; usecreate_or_alter()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 toFalse.
Examples
Deleting a task using its reference:
>>> task_reference.drop()
- drop_async(if_exists: bool | None = None) PollingOperation[None]ΒΆ
An asynchronous version of
drop().Refer to
PollingOperationfor more information on asynchronous execution and the return type.
- 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()
- execute_async(*, retry_last: bool = False) PollingOperation[None]ΒΆ
An asynchronous version of
execute().Refer to
PollingOperationfor more information on asynchronous execution and the return type.
- fetch() TaskΒΆ
Fetch the task resource.
Examples
Fetching a task using its reference:
>>> task = task_reference.fetch()
Accessing information of the task with task instance:
>>> print(task.name, task.comment)
- fetch_async() PollingOperation[Task]ΒΆ
An asynchronous version of
fetch().Refer to
PollingOperationfor more information on asynchronous execution and the return type.
- 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()
- fetch_task_dependents_async() PollingOperation[list[Task]]ΒΆ
An asynchronous version of
fetch_task_dependents().Refer to
PollingOperationfor more information on asynchronous execution and the return type.
- 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()
- get_complete_graphs_async(*, error_only: bool = True) PollingOperation[Iterable[TaskRun]]ΒΆ
An asynchronous version of
get_complete_graphs().Refer to
PollingOperationfor more information on asynchronous execution and the return type.
- 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()
- get_current_graphs_async() PollingOperation[Iterable[TaskRun]]ΒΆ
An asynchronous version of
get_current_graphs().Refer to
PollingOperationfor more information on asynchronous execution and the return type.
- resume() NoneΒΆ
Resume the task then it will run on the schedule.
Examples
Resume a task using its reference:
>>> task_reference.resume()
- resume_async() PollingOperation[None]ΒΆ
An asynchronous version of
resume().Refer to
PollingOperationfor more information on asynchronous execution and the return type.
- suspend() NoneΒΆ
Suspend the task so it wonβt run again on the schedule.
Examples
Suspend a task using its reference:
>>> task_reference.suspend()
- suspend_async() PollingOperation[None]ΒΆ
An asynchronous version of
suspend().Refer to
PollingOperationfor more information on asynchronous execution and the return type.