Snowflake resuming all tasks including children of a parent task

There are rules about the order or resumption, that make resuming parent and child task a pain, but here is a command that just resumes all tasks related to a parent.

SELECT SYSTEM$TASK_DEPENDENTS_ENABLE('MYTASK');
Show tasks <database.schema>;
show tasks analytics.dbt;

BTW, you must suspend a tasks with parents/children before dropping them – the same restriction does not exist for a single task with no children.

Here’s a bunch of code I used to test this:

DROP TABLE ANALYTICS.DBT.JUNK;
create table analytics.dbt.junk (id integer, junk_name varchar, create_date dateTIME);

DROP TASK MYTASK;
DROP TASK MYCHILDTASK;
create OR REPLACE task mytask
    warehouse = COMPUTE_WH
    schedule = 'using cron 0-59 * * * * EST'
  as
    INSERT INTO JUNK(ID, CREATE_DATE, JUNK_NAME) VALUES (28,CURRENT_TIMESTAMP, 'SOMESTRING');

create OR REPLACE task mychildtask
    warehouse = COMPUTE_WH
    after mytask
  as
    INSERT INTO JUNK(ID, CREATE_DATE, JUNK_NAME) VALUES (28,CURRENT_TIMESTAMP, 'SOMESTRING');


SELECT SYSTEM$TASK_DEPENDENTS_ENABLE('MYTASK');
SELECT SYSTEM$TASK_DEPENDENTS_DISABLE('MYTASK');

INSERT INTO JUNK(ID, CREATE_DATE, JUNK_NAME) VALUES (28,CURRENT_TIMESTAMP, 'SOMESTRING');

SELECT * FROM  ANALYTICS.DBT.JUNK;
SHOW TASKS IN ANALYTICS.DBT;
show tasks;

DROP TASK MYTASK;
ALTER TASK MYTASK SUSPEND;
ALTER TASK MYCHILDTASK SUSPEND;
ALTER TASK MYTASK RESUME;
ALTER TASK MYCHILDTASK RESUME;
SELECT CURRENT_TIMESTAMP;
SHOW TASKS;

// Use the table function "TASK_HISTORY()"
select *
  from table(information_schema.task_history())
  order by scheduled_time desc;

// See results for a specific Task in a given time
select *
from table(information_schema.task_history(
    scheduled_time_range_start=>dateadd('hour',-2,current_timestamp()),
    result_limit => 5,
    task_name=>'MYTASK'));

ALTER TASK MYCHILDTASK RESUME;
SELECT CURRENT_TIMESTAMP;

// Use the table function "TASK_HISTORY()"
select *
  from table(information_schema.task_history())
  order by scheduled_time desc;

// See results for a specific Task in a given time
select *
from table(information_schema.task_history(
    scheduled_time_range_start=>dateadd('hour',-4,current_timestamp()),
    result_limit => 5,
    task_name=>'CUSTOMER_INSERT2'));

Leave a Comment

Scroll to Top