snowflake.core.task.TaskResource | Snowflake Documentation (original) (raw)
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 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 inputtask
, 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" ... )
# Using a TaskCollection
to 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 PollingOperation for more information on asynchronous execution and the return type.
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()
drop_async(if_exists: bool | None = None) → PollingOperation[None]¶
An asynchronous version of drop().
Refer to PollingOperation for 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 PollingOperation for more information on asynchronous execution and the return type.
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 PollingOperation for 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 PollingOperation for 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 PollingOperation for 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, useget_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 PollingOperation for 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 PollingOperation for 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 PollingOperation for more information on asynchronous execution and the return type.