EXECUTE TASKΒΆ
Manually triggers an asynchronous single run of a task (either a standalone task or the root task in a task graph) independent of the schedule defined for the task.
A successful run of a root task triggers a cascading run of child tasks in the task graph as their precedent task completes, as though the root task had run on its defined schedule.
Additionally, you can manually trigger the re-execution of a previously failed task.
- See also:
SyntaxΒΆ
EXECUTE TASK <name>
EXECUTE TASK <name> RETRY LAST
ParametersΒΆ
name
Identifier for the standalone task or root task to run. If the identifier contains spaces or special characters, the entire string must be enclosed in double quotes. Identifiers enclosed in double quotes are also case-sensitive.
RETRY LAST
Re-execute the last failed task of the task graph with
name
restarting from where the tasks failed.To re-execute a task the following conditions must be met:
The last task graph run must be in state FAILED or CANCELED.
The task graph must not have been modified since it was last run.
The task graph must have been executed, or retried, in the last 14 days.
To view task history see either the TASK_HISTORY table function or Snowsight task history.
Note
RETRY LAST creates a new graph run which begins execution at the last failed task(s).
Specifically, all FAILED or CANCELED task runs are immediately re-executed, and associated child tasks are scheduled if all of their predecessors execute successfully.
Additionally the new task graph run produced by the retry will have an ATTEMPT NUMBER that is one greater than the previous failed graph run, and share the same GRAPH_RUN_GROUP_ID as the retried, or original task graph run.
Usage notesΒΆ
Executing a task requires either the OWNERSHIP or OPERATE privilege on the task.
When the EXECUTE TASK command triggers a task run, Snowflake verifies that the role with the OWNERSHIP privilege on the task also has the USAGE privilege on the warehouse assigned to the task, as well as the global EXECUTE TASK privilege; if not, an error is produced.
Tasks always run with the privileges of the original owner role, even if a different role with the OPERATE privilege uses EXECUTE TASK to run the task.
The SQL command can only execute a standalone task or the root task in a task graph. If a child task is input, the command returns a user error.
Manually executing a standalone or root task establishes a version of the task. The standalone task or entire task graph completes its run with this version. For more information about task versions, see Versioning of task runs.
A suspended root task is run without resuming the task; there is no need to explicitly resume the root task before you execute this SQL command. However, EXECUTE TASK does not automatically resume child tasks in the task graph. The command skips any child tasks that are suspended.
To recursively resume all dependent tasks tied to a root task in a task graph, query the SYSTEM$TASK_DEPENDENTS_ENABLE function rather than enabling each task individually (using ALTER TASK β¦ RESUME).
As a best practice when testing new or modified task graphs, set the root task to run on its intended production schedule but leave it in a suspended state. When you have tested the task graph successfully, resume the root task. Note that you must resume any suspended child tasks in the task graph for testing; otherwise, they are skipped during runs of the task graph.
If no instance of the task is running, a new run starts immediately.
If another instance is scheduled (that is, if the task shows a SCHEDULED state in the TASK_HISTORY output), the requested run replaces the scheduled run. The requested run starts immediately, using the current timestamp as the scheduled time.
If the task or task graph is currently queueing or executing (that is, if the task shows an EXECUTING state in the TASK_HISTORY output), then the current run continues using the task version that was current when the command was executed. A new run is then scheduled to start, at a time depending on the task type:
For standalone tasks, a new run is scheduled to start after the current run completes.
For task graphs:
If ALLOW_OVERLAPPING_EXECUTION = FALSE (default), a new run is scheduled to start after the current task graph completes.
If ALLOW_OVERLAPPING_EXECUTION = TRUE, and the currently executing task is a root task, a new run is scheduled to start after the root task completes.
If ALLOW_OVERLAPPING_EXECUTION = TRUE, and the currently executing task is a child task, a new run starts immediately.
If the EXECUTE TASK command is executed again before the next scheduled run starts, the requested run replaces the scheduled run.
If a task fails with an unexpected error, you can receive a notification about the error. For more information on configuring task error notifications refer to Enabling notifications for tasks.
To view the task information you can either:
Open Snowsight and select Monitoring Β» Task History.
Call the COMPLETE_TASK_GRAPHS table function, and examine the results.
ExamplesΒΆ
Manually trigger a run of a task named mytask
:
EXECUTE TASK mytask;