代码之家  ›  专栏  ›  技术社区  ›  aaron

将airflow scheduler作为守护进程运行时出现的问题

  •  14
  • aaron  · 技术社区  · 7 年前

    我有一个EC2实例,它运行airflow 1.8.0,使用 LocalExecutor . 根据这些文档,我预计以下两个命令之一会在守护进程模式下启动调度程序:

    airflow scheduler --daemon --num_runs=20

    airflow scheduler --daemon=True --num_runs=5

    但事实并非如此。第一个命令似乎可以工作,但在返回到终端之前,它只返回以下输出,而不生成任何后台任务:

    [2017-09-28 18:15:02,794] {__init__.py:57} INFO - Using executor LocalExecutor
    [2017-09-28 18:15:03,064] {driver.py:120} INFO - Generating grammar tables from /usr/lib/python3.5/lib2to3/Grammar.txt
    [2017-09-28 18:15:03,203] {driver.py:120} INFO - Generating grammar tables from /usr/lib/python3.5/lib2to3/PatternGrammar.txt
    

    airflow scheduler: error: argument -D/--daemon: ignored explicit argument 'True'
    

    这很奇怪,因为根据 docs --daemon=True 应该是 airflow scheduler

    挖得再深一点我就知道了 this StackOverflow post ,其中一个回复建议实施 systemd 用于根据以下可用代码将气流调度器作为后台进程进行处理: this repo

    我对剧本稍加修改后的版本发布如下。我用的是香草m4。使用Ubuntu 16.04.3的xlarge EC2实例:

    sudo systemctl enable airflow-scheduler
    sudo systemctl start airflow-scheduler
    

    什么都没发生。虽然我在这个实例上运行了更复杂的DAG, I am using this dummy case 创建一个简单的测试,它也可以作为侦听器,让我知道调度程序何时按计划运行。

    我一直在使用 journalctl -f 调试。下面是调度程序进程的几行输出。没有明显的问题,但我的任务没有执行,没有为测试DAG生成日志,这将帮助我放大错误。这里有什么问题吗?

    Sep 28 18:39:30 ip-172-31-15-209 airflow[20603]: [2017-09-28 18:39:30,965] {dag_processing.py:627} INFO - Started a process (PID: 21822) to generate tasks for /home/ubuntu/airflow/dags/scheduler_test_dag.py - logging into /home/ubuntu/airflow/logs/scheduler/2017-09-28/scheduler_test_dag.py.log
    Sep 28 18:39:31 ip-172-31-15-209 airflow[20603]: [2017-09-28 18:39:31,016] {jobs.py:1002} INFO - No tasks to send to the executor
    Sep 28 18:39:31 ip-172-31-15-209 airflow[20603]: [2017-09-28 18:39:31,020] {jobs.py:1440} INFO - Heartbeating the executor
    Sep 28 18:39:32 ip-172-31-15-209 airflow[20603]: [2017-09-28 18:39:32,022] {jobs.py:1404} INFO - Heartbeating the process manager
    Sep 28 18:39:32 ip-172-31-15-209 airflow[20603]: [2017-09-28 18:39:32,023] {jobs.py:1440} INFO - Heartbeating the executor
    Sep 28 18:39:33 ip-172-31-15-209 airflow[20603]: [2017-09-28 18:39:33,024] {jobs.py:1404} INFO - Heartbeating the process manager
    Sep 28 18:39:33 ip-172-31-15-209 airflow[20603]: [2017-09-28 18:39:33,025] {dag_processing.py:559} INFO - Processor for /home/ubuntu/airflow/dags/capone_dash_dag.py finished
    Sep 28 18:39:33 ip-172-31-15-209 airflow[20603]: [2017-09-28 18:39:33,026] {dag_processing.py:559} INFO - Processor for /home/ubuntu/airflow/dags/scheduler_test_dag.py finished
    

    气流调度器 手动操作一切正常。因为我的测试DAG的开始日期是9月9日,所以从那时起它每分钟都在回填,生成一个运行时间计时器。当我使用 系统D

    有什么想法吗?

    2 回复  |  直到 7 年前
        1
  •  38
  •   aaron    7 年前

    我通常按以下方式启动气流

    airflow kerberos -D
    airflow scheduler -D
    airflow webserver -D
    

    这是 airflow webeserver --help

    -D、 --守护进程Daemonize,而不是在前台运行

    注意,这里不可能有布尔标志。文件必须固定。

    airflow scheduler -D 失败:

    这包括在评论中,但在这里似乎值得一提。当您运行气流调度器时,它将创建文件 $AIRFLOW_HOME/airflow-scheduler.pid $AIRFLOW_HOME/airflow-scheduler.err 这会告诉你 lockfile.AlreadyLocked: /home/ubuntu/airflow/airflow-scheduler.pid is already locked . 如果您的调度程序守护进程确实已停止运行,并且您发现自己需要重新启动,请执行以下命令:

    sudo rm $AIRFLOW_HOME airflow-scheduler.err  airflow-scheduler.pid
    airflow scheduler -D 
    

    这让我的日程安排重回正轨。

        2
  •  3
  •   MSemochkin    7 年前

    PATH=/home/ubuntu/bin:/home/ubuntu/.local/bin:$PATH
    

    PATH=/home/ubuntu/bin:/home/ubuntu/.local/bin
    

    因此,变量 PATH 不包含 /bin 这是一个 bash LocalExecutor用于运行任务的实用程序。

    AIRFLOW_HOME . 也就是说,气流正在其中查找其配置文件的目录。