Search code examples
airflowairflow-scheduler

I am not able to use start date and end date in clear airflow through CLI


I have been trying to clear a task using the following command. airflow clear -t <task_name> -s <start_date> -e <end_date> <dag_name>

eg: airflow clear -t <task_name> -s 2020-06-22 -e 2020-06-22 <dag_name>

I have also tried to use start date and end date with all the following combinations:

  1. '2020-06-22'
  2. '2020-06-22 10:21:23'
  3. 2020-06-23T10:28:15
  4. 2020-06-23T07:44:27.814321+00:00

None of these combinations is working for me. I don't understand how to use start_date and end_date with the clear command. I also want to know if we can clear the tasks between the start date and end date.


Solution

  • You dateformat YYYY-mm-dd is correct but tasks to be clear should be within start_date <= {execution date of the tasks} < end_date so you need to change your end_date.

    airflow clear -s 2020-06-22 -e 2020-06-23 sample_dag
    

    This will clear all tasks within sample_dag.

    If you want to clear a specific task(s) within the sample_dag, you can use the -t option. -t option takes the regex, for example

    airflow clear -t etl -s 2020-06-22 -e 2020-06-23 sample_dag
    

    will clear all tasks that contains "etl" in task_id.