2
votes

I am currently working on a snowflake "task" to upsert a table every day in the early hours.

My current task is created using the below syntax -

CREATE OR REPLACE TASK "DB"."SCHEMA"."SAMPLE_TASK"
  WAREHOUSE = SAMPLE_WAREHOUSE
  SCHEDULE = 'USING CRON * 12 * * * UTC'
  TIMESTAMP_INPUT_FORMAT = 'YYYY-MM-DD HH24'
AS
  CREATE OR REPLACE "DB"."SCHEMA"."EMP"
  AS 
  SELECT * FROM "DB"."SCHEMA"."EMP_STAGE";

I work in CST, and with UTC being -7 hrs, my task was expected to run at 5am in the morning, which it did. I confirmed that using "TASK_HISTORY" in the INFORMATION_SCHEMA -

SELECT * FROM TABLE(DB.INFORMATION_SCHEMA.TASK_HISTORY()) WHERE NAME = 'SAMPLE_TASK';

But it also ran for an extra 59 times for every minute of the remaining hour until 6.

  • Initial QueryID timestamp - 2020-07-02 05:00:00.000 -0700
  • Final QueryID timestamp - 2020-07-02 05:59:00.000 -0700

Am I missing anything here?

Thanks for reading through, any help is greatly appreciated.

-Sri

2

2 Answers

2
votes

The schedule is in cron format, and you have a * for the minute, so it'll run every minute for that hour.

Cron format details can be found on many pages in the web, one example is as follows, notice the first "parameter" into the cron format is the minute:

https://support.acquia.com/hc/en-us/articles/360004224494-Cron-time-string-format

I recommend rebuilding that task with a value of zero or one for that first *.

I hope this helps...Rich

1
votes

Your task's CRON syntax is requesting, by specifying a * for its minute (first) component, the task to be executed every minute within the 12th hour of the day (i.e. 60 times per day, all in the 12th hour).

Based on your description, what you seek is the following instead:

SCHEDULE = 'USING CRON 0 12 * * * UTC'

This will execute only once at 1200 hours UTC each day.

Using a tool like crontab guru or CRON tester can help test your CRON schedules before you implement them into your Snowflake tasks.