我有一个EC2实例正在使用LocalExecutor运行Airflow 1.8.0。根据这些文档,我希望以下两个命令中的一个会在守护程序模式下引发调度程序:
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,以便根据可用的代码将气流调度程序作为后台进程来处理。
我对剧本稍加修改后的内容发布如下。我在Ubuntu 16.04.3中使用的是Vanilla M4.xlarge EC2实例:
this repo
/etc/sysconfig/airflow
/user/lib/systemd/system/airflow-scheduler.service
从那里我打电话给:
sudo systemctl enable airflow-scheduler
sudo systemctl start airflow-scheduler

什么也没发生。虽然我在这个实例上运行的DAG更复杂,/etc/tmpfiles.d/airflow.conf创建一个简单的测试,它还充当监听器,让我知道调度程序何时按计划运行。
我一直在使用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

当我手动运行airflow scheduler时,一切正常。由于我的测试DAG的开始日期是9月9日,所以从那时起,它每分钟都会进行一次回填,生成一个运行时间指示器。但是,当我使用systemd将调度程序作为守护程序运行时,它是完全安静的,没有明显的错误源。
有什么想法吗?

最佳答案

文件可能注明日期?
我通常按以下方式启动气流

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

以下是airflow webeserver --help输出(从1.8版开始):
-d,-daemon守护进程,而不是在前台运行
注意这里没有布尔标记。文件必须固定。
如果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

这使我的调度器恢复正常。

关于python - 将 Airflow 调度程序作为守护进程运行的问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46476246/

10-16 00:52