2 weeks ago
Hi,
I am looking to schedule a workflow to execute on 3rd working day. Working day here would be Mon-Fri of each month. I could not find any direct crontab solution but have created watcher file solution for it. Below code will create a watcher file at every 3rd working day of the month and this code is added as a task in workflow and subsequent tasks in the workflow will be dependent on it. The problem in this solution is that I will have to schedule this workflow at least 4-5 times every month because 8th working day will fall in between 9-14th of every month and out of these 4-5 times only 1 time it would succeed and rest 4 will appear as failed job in workflow history which is never a good design. Can somebody help me here? It would be great help.
a week ago
Hi Vishal
Youโre right: thereโs no single Quartz cron expression that says โrun on the 3rd working day (MonโFri) of every monthโ. Quartz can handle โNth weekday of monthโ (like 3#1 = first Wednesday), but not โNth business day regardless of weekdayโ, so you do need a bit of logic around it
The good news: you donโt need 4โ5 schedules or a bunch of failed runs in history. You can:
Schedule the workflow every weekday, and
Use a small โgateโ task to decide whether to continue or skip that day
Make non-3rd-working-day runs show as Succeeded & Skipped, not Failed.
Have a look here
In the job trigger, use a weekday schedule, for example:
In the UI: Advanced schedule โ Every MonโFri at 09:00
Cron example: 0 0 9 ? * MON-FRI
This way the job runs daily on business days only.
Make your current notebook the first task in the workflow (e.g. check_3rd_workday).
Slightly tweak it so that:
It sets a task value with the result
It exits successfully on non-3rd days (no exception), so the run is green, not red.
Example:
Key points:
dbutils.notebook.exit(...) ends the task as success (unless you raise an exception).
dbutils.jobs.taskValues.set(...) lets downstream tasks read is_third_workday.
So your run history will show this task as green every weekday; the โnon-3rdโ days are just short runs that exit early.
You have two main options:
If your workspace has the If/else condition task:
First task: check_3rd_workday (the notebook above).
Second task: type = If/else condition, expression like:
{{tasks.check_3rd_workday.values.is_third_workday}} == "true"
Attach your real workflow tasks to the true branch only.
Result:
On the 3rd working day: condition = true โ branch with your main pipeline runs.
Other days: condition = false โ that branch stays skipped; entire job shows as succeeded with most tasks greyed out.
a week ago
Hi Vishal
Youโre right: thereโs no single Quartz cron expression that says โrun on the 3rd working day (MonโFri) of every monthโ. Quartz can handle โNth weekday of monthโ (like 3#1 = first Wednesday), but not โNth business day regardless of weekdayโ, so you do need a bit of logic around it
The good news: you donโt need 4โ5 schedules or a bunch of failed runs in history. You can:
Schedule the workflow every weekday, and
Use a small โgateโ task to decide whether to continue or skip that day
Make non-3rd-working-day runs show as Succeeded & Skipped, not Failed.
Have a look here
In the job trigger, use a weekday schedule, for example:
In the UI: Advanced schedule โ Every MonโFri at 09:00
Cron example: 0 0 9 ? * MON-FRI
This way the job runs daily on business days only.
Make your current notebook the first task in the workflow (e.g. check_3rd_workday).
Slightly tweak it so that:
It sets a task value with the result
It exits successfully on non-3rd days (no exception), so the run is green, not red.
Example:
Key points:
dbutils.notebook.exit(...) ends the task as success (unless you raise an exception).
dbutils.jobs.taskValues.set(...) lets downstream tasks read is_third_workday.
So your run history will show this task as green every weekday; the โnon-3rdโ days are just short runs that exit early.
You have two main options:
If your workspace has the If/else condition task:
First task: check_3rd_workday (the notebook above).
Second task: type = If/else condition, expression like:
{{tasks.check_3rd_workday.values.is_third_workday}} == "true"
Attach your real workflow tasks to the true branch only.
Result:
On the 3rd working day: condition = true โ branch with your main pipeline runs.
Other days: condition = false โ that branch stays skipped; entire job shows as succeeded with most tasks greyed out.
a week ago
Use dbutils notebook exit("SKIP") instead of exiting with an error.
In Databricks Workflows:
EXIT with "SKIP" โ treated as SKIPPED
EXIT with "STOP" or raising an exception โ counted as FAILED
Modify your code like this:
if business_day_count == 3:
print("Today is the 3rd working day โ Continue workflow")
else:
print("Not the 3rd working day โ Skip workflow")
dbutils.notebook.exit("SKIP")
Now your workflow can be scheduled every weekday without generating failures.
This is the simplest fix.
Thursday
Hi @bianca_unifeye , @Poorva21 ,
Thank you for your valuable responses.
I have changed the main workflow trigger as file arrival in scheduling. I have scheduled the watcher file code to run daily in weekdays and as soon as the 3rd working day encounters it creates a trigger file in the container, and the dependent workflow will sense the file arrival and will trigger the job. In this way the main workflow will be triggered only once, and no error will be logged in Job history.
Thank you,
Vishal
Passionate about hosting events and connecting people? Help us grow a vibrant local communityโsign up today to get started!
Sign Up Now