Workflow scheduling on particular working day of the month in ADB

maurya_vish24
New Contributor II

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.

 

#code to check if the calander date is working day 9 or not

from datetime import datetime, timedelta
import calendar
import sys
 
today = datetime.today()
year = today.year
month = today.month
 
# Count business days from start of month until today
business_day_count = 0
current = datetime(year, month, 1)
 
while current <= today:
    if current.weekday() < 5:  # 0=Mon ... 4=Fri
        business_day_count += 1
    current += timedelta(days=1)
 
print(f"Today is business day #{business_day_count}")
 
if business_day_count == 3:
    print("Today is the rd working day → Continue workflow")
    date_stamp = datetime.now().strftime("%Y%m%d")
    # Create file path with timestamp
    file_path = f"/mnt/refined/workday_check/pipeline_log_{date_stamp}.txt"
    # Create empty file using dbutils.fs.put
    dbutils.fs.put(file_path, "")
    #dbutils.notebook.exit("STOP")
else:
    print("Not the 3rd working day → Stop workflow")
    dbutils.notebook.exit("STOP")
 
Thanks,
Vishal