Search code examples
snowflake-cloud-data-platformsnowflake-task

Is there a way to force run a Snowflake's TASK now (before the next scheduled slot)?


I have a task scheduled to run every 15 minutes:

CREATE OR REPLACE TASK mytask
  WAREHOUSE = 'SHARED_WH_MEDIUM'
  SCHEDULE = '15 MINUTE'
  STATEMENT_TIMEOUT_IN_SECONDS = 3600,
  QUERY_TAG = 'KLIPFOLIO'
AS
  CREATE OR REPLACE TABLE mytable AS
   SELECT * from  xxx; 
;

alter task mytask resume;

I see from the output of task_history() that the task is SCHEDULED:

select * from table(aftonbladet.information_schema.task_history(task_name => 'MYTASK')) order by scheduled_time;
QUERY_ID    NAME    DATABASE_NAME   SCHEMA_NAME QUERY_TEXT  CONDITION_TEXT  STATE   ERROR_CODE  ERROR_MESSAGE   SCHEDULED_TIME  COMPLETED_TIME  RETURN_VALUE
***     MYTASK  *** *** ***     SCHEDULED           2020-01-21 09:58:12.434 +0100       

but I want it to run right now without waiting for the SCHEDULED_TIME , is there any way to accomplish that?


Solution

  • Snowflake now supports running tasks manually. Just use the EXECUTE TASK command:

    EXECUTE TASK manually triggers an asynchronous single run of a scheduled task (either a standalone task or the root task in a task tree) independent of the schedule defined for the task. A successful run of a root task triggers a cascading run of child tasks in the tree as their precedent task completes, as though the root task had run on its defined schedule.

    Also, there is no need for the task in started mode. Even tasks in suspended mode can be executed manually.