Tuesday, July 26, 2022

[SOLVED] Running a Snowflake Task on the first non-weekend day of the month (using cron)

Issue

Right now, I only know how to set it to the first of the month (irrespective of whether it's a weekend). The sample code from the task is a follows:

SCHEDULE = 'USING CRON 0 2 1 * * Europe/Dublin'

Solution

I don't think it is possible to schedule a task to run on the first non-weekend day of the month.

Workaround:

  1. Schedule your job to run on days 1-3 and call a stored procedure
  2. Inside your SP, check if the job is already executed this month (you may use a table to persist the last run)
  3. Insider your SP, check if it's a weekday, else end the SP without executing the rest of the task


Answered By - Gokhan Atil
Answer Checked By - Marie Seifert (WPSolving Admin)