EXECUTE TASK

statementsupportedUDFs, procedures, tasks, alerts, scripting

docs.snowflake.com ↗

Manually triggers a 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. By default, the command runs asynchronously and returns after scheduling the run. Specify AWAIT to wait for the task or task graph to complete before the command returns. 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.

Syntax

supportedpartialnot supportednot scored

EXECUTE TASK <name>
  [ USING CONFIG = <configuration_string> ]
  [ AWAIT ]

EXECUTE TASK <name> RETRY LAST

EXECUTE TASK <name> RETRY GRAPH RUN GROUP '<graph_run_group_id>'

Parameters

NameRequiredDescription
nameIdentifier 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.
USING CONFIG = configuration_stringSpecifies a configuration string in valid JSON format for this single execution. This parameter creates a new execution with the dynamically specified configuration, but doesn’t modify the task definition. Snowflake merges the dynamic configuration with the default configuration, which is the CONFIG parameter that you set in the task definition with CREATE or ALTER. For matching fields, Snowflake uses the dynamically specified values. For non-matching fields, Snowflake uses the values from the default configuration. For an example, see Use a dynamic CONFIG. The configuration string follows the same format as the CONFIG parameter in CREATE TASK or ALTER TASK:Copy code CONFIG = $${"string1": value1 [, "string2": value2, ...] }$$ Example:Copy code CONFIG = $${"learning_rate": 0.2, "environment": "testing"}$$ To wait for a run with this configuration to complete, specify AWAIT after the configuration string. For details, see Synchronous execution with AWAIT.
AWAITRuns the task or task graph synchronously and waits for the run to complete. For run behavior, timeouts, and output, see Synchronous execution with AWAIT.
RETRY LASTRe-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 last failed graph run’s first attempt must have been executed in the last 14 days. To view task history, see either the TASK_HISTORY table function or the Tasks page on Snowsight. 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.
RETRY GRAPH RUN GROUP 'graph_run_group_id'Re-execute starting from the failed tasks of a specific previous graph run, identified by its GRAPH_RUN_GROUP_ID. Use this variant when you want to retry a specific graph run rather than the most recent one. RETRY LAST always targets the latest run. To re-execute a graph run the following conditions must be met: The latest run of the specified graph run group must be complete (it must not have a run still in progress) and must have at least one task in state FAILED or CANCELED. The specified graph run group must belong to the task identified by name. The task graph must not have been modified since the targeted run. The targeted graph run group’s first attempt must have been executed in the last 14 days. To find a graph run’s GRAPH_RUN_GROUP_ID, query the TASK_HISTORY or COMPLETE_TASK_GRAPHS table function, or use the Tasks page on Snowsight. Note Like RETRY LAST, this command creates a new graph run that begins execution at the failed task(s) of the targeted graph run. Specifically, all FAILED or CANCELED task runs in the targeted graph run are immediately re-executed, and associated child tasks are scheduled if all of their predecessors execute successfully. The new task graph run produced by the retry will have an ATTEMPT_NUMBER that is one greater than the targeted graph run, and shares the same GRAPH_RUN_GROUP_ID as the targeted graph run.

Usage notes

Output

By default, EXECUTE TASK returns a status message after scheduling the run. With AWAIT, a successful or skipped run returns one row with the following columns: Column | Description MESSAGE | A message indicating that the task or task graph completed or was skipped. GRAPH_RUN_GROUP_ID | The identifier for the graph run group started by the command. You can use it to query the TASK_HISTORY, CURRENT_TASK_GRAPHS, or COMPLETE_TASK_GRAPHS table function. STATUS | SUCCEEDED or SKIPPED. If the run fails or is canceled, the command returns an error instead of a result row. The error includes the graph run group ID and, when available, error details. You can use the graph run group ID to query task history for details.

See also