15

I have beening working on Airflow for a while for no problem withe the scheduler but now I have encountered a problem.

Bascially I have a script and dag ready for a task, but the task doesn't run periodically. Instead it needs to be activated at random time. (External parties will tell us it's time and we will run it. This may happen for many times in the following months.)

Is there anyway to trigger the dag manually? Any other directions/suggestions are welcomed as well. Thanks.

user1799438
  • 151
  • 1
  • 1
  • 3

4 Answers4

18

You have a number of options here:

You'll probably go with the UI or CLI if this is truly going to be 100% manual. The API or Operator would be options if you are looking to let the external party indirectly trigger it themselves. Remember to set schedule_interval=None on the DAG.

Thomas Dickson
  • 313
  • 3
  • 9
Daniel Huang
  • 6,238
  • 34
  • 33
2

So a dag can be triggered by following ways:

  • Using the REST API Reference(see documentation)

    endpoint-

    > POST   /api/experimental/dags/<DAG_ID>/dag_runs
    
    1. Using Curl:

      curl -X POST
      http://localhost:8080/api/experimental/dags/<DAG_ID>/dag_runs
      -H 'Cache-Control: no-cache'
      -H 'Content-Type: application/json'
      -d '{"conf":"{"key":"value"}"}'

    2. Using Python requests:

         import requests
         response = requests.post(url, data=json.dumps(data), headers=headers)
      
  • Using the trigger DAG option present in the UI as mentioned by @Daniel

Anonymous
  • 55
  • 7
1

Airflow has API. The method you need is POST /api/experimental/dags/<DAG_ID>/dag_runs. With this method you also could pass config params for the dag run.

We use Jenkins to trigger dags manually. If you are using Jenkins you could check our jenkins pipeine library.

shuvalov
  • 4,713
  • 2
  • 20
  • 17
1

The examples given from other answers use the “experimental” API. This REST API is deprecated since version 2.0. Please consider using the stable REST API.

Using method POST dags/<DAG_ID>/dagRuns.

curl -X POST 'http://localhost:8080/api/v1/dags/<DAG_ID>/dagRuns' \
    --header 'accept: application/json' \
    --header 'Content-Type: application/json' \
    --user '<user>:<password>' \   # If authentication is used
    --data '{}'
privod
  • 209
  • 5
  • 7