- Schema:
TASK_HISTORY View¶
This Account Usage view enables you to retrieve the history of task usage within the last 365 days (1 year), where this history metadata is available. The view displays one row for each run of a task in the history.
Columns¶
Column Name |
Data Type |
Description |
---|---|---|
QUERY_ID |
TEXT |
ID of the SQL statement executed by the task. Can be joined with the QUERY_HISTORY view for additional details about the execution of the statement or stored procedure. |
NAME |
TEXT |
Name of the task. |
DATABASE_NAME |
TEXT |
Name of the database that contains the task. |
SCHEMA_NAME |
TEXT |
Name of the schema that contains the task. |
QUERY_TEXT |
TEXT |
Text of the SQL statement. |
CONDITION_TEXT |
TEXT |
Text of WHEN condition the task evaluates when determining whether to run. |
STATE |
TEXT |
Status of the completed task: SUCCEEDED, FAILED, or CANCELLED. Starting in November 2020, the view also returns tasks with a SKIPPED state. Note that the view does not return SCHEDULED or EXECUTING task runs. To retrieve the task history details for runs in a scheduled or executing state, query the TASK_HISTORY table function in the Information Schema. |
ERROR_CODE |
NUMBER |
Error code, if the statement returned an error. |
ERROR_MESSAGE |
TEXT |
Error message, if the statement returned an error. |
SCHEDULED_TIME |
TIMESTAMP_LTZ |
Time when the task is/was scheduled to start running. Note that we make a best effort to ensure absolute precision, but only guarantee that tasks do not execute before the scheduled time. |
QUERY_START_TIME |
TIMESTAMP_LTZ |
Time when the query in the task definition started to run. This timestamp aligns with the start time for the query returned by QUERY_HISTORY. |
COMPLETED_TIME |
TIMESTAMP_LTZ |
Time when the task completed. |
ROOT_TASK_ID |
TEXT |
Unique identifier for the root task in a tree of tasks. This ID matches the ID column value in the SHOW TASKS output for the same task. |
GRAPH_VERSION |
NUMBER |
Integer identifying the version of the tree of tasks that was run, or is scheduled to be run. Each incremental increase in the value represents one or more modifications to tasks in the tree. If the root task is recreated (using CREATE OR REPLACE TASK), then the version number restarts from 1. |
RUN_ID |
NUMBER |
Time when the standalone or root task in a tree of tasks is/was originally scheduled to start running. Format is epoch time (in milliseconds). The combination of the ROOT_TASK_ID and RUN_ID values identifies a specific run of a task tree. . Original scheduled time refers to rare instances when the system may reschedule the same task to run at a different time to retry it or rebalance the load. If that happens, RUN_ID shows the original scheduled run time and SCHEDULED_TIME shows the rescheduled run time. |
RETURN_VALUE |
TEXT |
Value set for the predecessor task in a tree of tasks. The return value is explicitly set by calling the SYSTEM$SET_RETURN_VALUE function by the predecessor task. |
Usage Notes¶
Latency for the view may be up to 45 minutes.
For increased performance, filter queries on the COMPLETED_TIME or SCHEDULED_TIME column. See the Examples section (in this topic).
Examples¶
Retrieve records for the 10 most recent completed task runs:
SELECT * FROM snowflake.account_usage.task_history LIMIT 10;
Retrieve records for task runs completed in the past hour:
SELECT * FROM snowflake.account_usage.task_history WHERE COMPLETED_TIME > DATEADD(hours, -1, CURRENT_TIMESTAMP());