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 inputtask
, the property will be set toNULL
in Snowflake too because itβs regarded as the expected value.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_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 toFalse
.
Examples
Deleting a task using its reference:
>>> task_reference.drop()
- 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()
- 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_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()
- 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_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()
- resume() None ΒΆ
Resume the task then it will run on the schedule.
Examples
Resume a task using its reference:
>>> task_reference.resume()
- suspend() None ΒΆ
Suspend the task so it wonβt run again on the schedule.
Examples
Suspend a task using its reference:
>>> task_reference.suspend()