snowflake-cloud-data-platformscheduled-tasks

How to schedule a task using Snowflake


I am trying to use a task in Snowflake to execute a stored procedure at 45 minutes past the hour every hour. I set the CRON time to the below but when testing to see if it is running, it is not. Am I missing something in the requirements for the task?

WAREHOUSE=WH_XS
--SCHEDULE='USING CRON 0 6 * * * UTC' -- you can change schedule as per your needs
SCHEDULE='USING CRON 45 * * * * UTC'

AS BEGIN

CALL SP_LOAD_PKG_LAB_SKU_LIST();

END;

Solution

  • You can create a task using the below piece of code

    CREATE TASK mytask_hour 
    WAREHOUSE = mywh 
    SCHEDULE = 'USING CRON 0 9-17 * * SUN America/Los_Angeles' 
    AS
    CALL SP_LOAD_PKG_LAB_SKU_LIST();
    

    https://docs.snowflake.com/en/sql-reference/sql/create-task

    Once the task is created, you should resume the task, for the task to execute as per the schedule

    ALTER TASK mytask_hour RESUME;
    

    https://docs.snowflake.com/en/sql-reference/sql/alter-task#examples

    EXECUTE TASK <name>;
    

    Manually triggers an asynchronous 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.

    https://docs.snowflake.com/en/sql-reference/sql/execute-task

    SHOW TASKS; 
    

    will list the tasks and certain associated details https://docs.snowflake.com/en/sql-reference/sql/show-tasks