0

I need to execute the airflow same task on 12th day of the month and 2 days before the last day of the month.

I was trying with macros and execution_date as well. Not sure how to proceed further. Could you please help on this?

def check_trigger(execution_date, day_offset, **kwargs):
    target_date = execution_date - timedelta(days = day_offset)
    return target_date
munsifali
  • 1,732
  • 2
  • 24
  • 43
Murugesan
  • 15
  • 1
  • 4
  • For scheduling criteria that cannot be realised via `crontab` expressions, you can always rely on *programming-logic*: [skip](https://stackoverflow.com/a/57108259/3679900) task(s) when you don't want to run them. – y2k-shubham Oct 01 '19 at 17:27

1 Answers1

0

I would approach it like below. And twelfth_or_two_before is a Python function that simply checks the date & returns the task_id of the appropriate downstream task. (That way if the business needs ever change & you need to run the actual tasks on a different/additional day(s), you just modify that function.)

with DAG( ... ) as dag:
    right_days = BranchPythonOperator(
        task_id="start",
        python_callable="twelfth_or_two_before,
    )
    do_nothing = DummyOperator(task_id="do_nothing")
    actual_task = ____Operator( ... )  # This is the Operator that does actual work
    start >> [do_nothing, actual_task]
lalligood
  • 144
  • 8