运行dag并运行airflow:错误:需要以下参数:task_id,execution_date

时间:2019-03-20 05:51:54

标签: airflow

鉴于我有一个easteregg.py文件:

from airflow import DAG

from dateutil import parser
from datetime import timedelta, datetime, time
from airflow.operators import PythonOperator
from airflow.operators.dummy_operator import DummyOperator
from easteregg import easteregg_workflows as wf

defaults = {
    'owner': "JohnDoe",
    'depends_on_past': False,
    'email': ['john.doe@mail.com'],
    'email_on_failure': True,
    'email_on_retry': False,
    'retries': 1,
    'retry_delay': timedelta(minutes=15),
    'start_date': parser.parse('2019-01-01 00:00:00')
}

dag = DAG('easteregg', default_args=defaults, 
    schedule_interval="*/5 * * * *")


step1 = PythonOperator(
    task_id="step1",
    python_callable=wf.run1,
    default_args=defaults,
    provide_context=True,
    pool="pool",
    dag=dag)

step0 = DummyOperator(
    task_id="step0",
    dag=dag)

step0 >> step1

easteregg_workflows.py文件很简单:

def run1(**kwargs):
    logging.info("Hello airflow 1")

我现在想简单地触发气流作业。所以我发出了命令:

airflow run easteregg

但是它抛出了一个错误airflow run: error: the following arguments are required: task_id, execution_date

我需要什么才能使DAG运行?

1 个答案:

答案 0 :(得分:1)

您的dag文件没有任何丢失。 airflow run easteregg是不正确的命令。 airflow run并没有中断。而是运行task_id

尝试使用airflow run -h

usage: airflow run [-h] [-sd SUBDIR] [-m] [-f] [--pool POOL]
                   [--cfg_path CFG_PATH] [-l] [-A] [-i] [-I] [--ship_dag]
                   [-p PICKLE] [-int]
                   dag_id task_id execution_date

气流需要dag_id,task_id和execute_date

  

位置参数:
  dag_id dag的ID
  task_id任务的ID
   execute_date DAG的执行日期

您可以使用trigger_dag命令来代替运行dag。 https://airflow.apache.org/cli.html

airflow trigger_dag easteregg

Usage:airflow trigger_dag [-h] [-sd SUBDIR] [-r RUN_ID] [-c CONF] [-e EXEC_DATE]
                    dag_id