0

I Created TASK like below

CREATE OR REPLACE TASK test_task
WAREHOUSE = TEST_WH
SCHEDULE = '1 MINUTE'
AS
BEGIN
 CALL SP_TASKEXECUTION('CREATE_TABLE_PROC_NAME');
END;

I see task created and in suspended state. Now i ran ALTER TASK test_task to RESUME the task. Now im seeing the task status as started. But it is not running. Also i tried to EXECUTE the task Still it is in started state

SP_TASKEXECUTION : This procedure takes another procedure name as input and execute.

CREATE_TABLE_PROC_NAME : This procedure contains create or replace table statment.

Both are working fine when i executes manually. but when it is scheduled through tasks it got stuck in started state .

My question is what can be the possible reasons and how to fix this?

2
  • Hi, did you check if you are able to run the procedure CREATE_TABLE_PROC_NAME , without calling from a task ? Commented Feb 3 at 14:58
  • OP did mention that the procedures on their own works fine. Both are working fine when i executes manually
    – samhita
    Commented Feb 3 at 16:41

2 Answers 2

0

If you are only checking TASK status using SHOW TASKS, then it only has two state as per documentation.

‘started’ or ‘suspended’ based on the current state of the task.

I think you would want to check TASK_HISTORY view which should show the previously executed tasks.

Sample query from documentation

    SELECT query_text, completed_time
FROM snowflake.account_usage.task_history
ORDER BY completed_time DESC
LIMIT 10;

Note as per documentation :

Latency for the view may be up to 45 minutes.

6
  • Thanks for the response. when i check the TASK_HISTORY. Im not seeing any records in that. After sometime task is moving to suspend state from started state with the reason SUSPENDED_DUE_TO_ERROR. But im not finding the exact reason why it is moved to suspended state. Im able to see this info when i run SHOW TASKS command only.
    – phani437
    Commented Feb 3 at 12:10
  • not sure if you are accessing with ACCOUNTADMIN role, but do check the usage section here, you need to have certain role if you are accessing directly the table. This function returns results only for the ACCOUNTADMIN role, the task owner, or a role with the global MONITOR EXECUTION privilege. Note that unless a role with the MONITOR EXECUTION privilege also has the USAGE privilege on the database and schema that store the task, the DATABASE_NAME and SCHEMA_NAME values in the output are NULL.
    – samhita
    Commented Feb 3 at 12:22
  • I edited the answer with task_history view from snowflake.account_usage.task_history => This one has a latency of 45 minutes @phani437
    – samhita
    Commented Feb 3 at 12:24
  • When we need to know the outcome of a task immediately, we go into the Snowsight Console. You can select the MONITORING group from the left menu when you start up, and you can select the query history. You'll have to remove the filter for your specific username, and you'll also have to go into the FILTERS dropdown and turn on Queries executed by user tasks. This will give you what's happening in near real time. Commented Feb 3 at 17:47
  • This is resolved. Thanks @samhita
    – phani437
    Commented Mar 20 at 16:43
0

SHOW tasks will show only 2 states ‘started’ or ‘suspended’. To view the past executions of task Realtime(without latency) task data of previous 7 days: https://docs.snowflake.com/en/sql-reference/functions/task_history

Task data for last 1 year with 45 minute latency: https://docs.snowflake.com/en/sql-reference/account-usage/task_history

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.