snowflake.core.task.TaskResource

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

Bases: SchemaObjectReferenceMixin[TaskCollection]

A reference to a specific Task resource in Snowflake.

Example

>>> tasks: TaskCollection = root.databases["mydb"].schemas["myschema"].tasks
>>> mytask = tasks["mytask"]
>>> # Then call other APIs to manage this task.
>>> mytask.resume()
>>> mytask.suspend()
Copy

Attributes

database
fully_qualified_name
root
schema

Methods

__init__(name: str, collection: TaskCollection) None
create_or_update(task: Task) None

Create or update a task in the Snowflake database.

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 – an instance of Task.

Example

>>> from snowflake.core import Root
>>> root = Root(session)
>>> tasks: TaskCollection = root.databases["mydb"].schemas["myschema"].tasks
>>> mytask = tasks.create(Task("mytask", definition="select 1"))
>>> mytask_entity = mytask.fetch()
>>> mytask_entity.definition = "select 2"
>>> tasks["mytask"].create_or_update(mytask_entity)
Copy
delete() None

Delete the task from Snowflake.

execute(*, retry_last: bool = False) None

Execute the task immediately without waiting for the schedule.

Parameters:

retry_last – Re-execute the last failed task of the DAG.

fetch() Task

Fetch the task details from Snowflake.

fetch_task_dependents() List[Task]

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

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().

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().

resume() None

Resume the task then it will run on the schedule.

suspend() None

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

语言: 中文