将气流计划程序作为后台进程运行时出现的问题

2024-06-13 16:57:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个EC2实例正在使用LocalExecutor运行Airflow1.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,以便根据this repo提供的代码将气流调度器作为后台进程处理。

我对这个脚本稍加编辑的修改如下。我在Ubuntu16.04.3上使用vanilla m4.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

当我手动运行airflow scheduler时,一切正常。因为我的测试DAG的开始日期是9月9日,所以从那以后,它每分钟都在恢复,生成一个运行时间计时器。但是,当我使用systemd作为deamon运行调度程序时,它是完全安静的,没有明显的错误源。

有什么想法吗?


Tags: thepy程序ipinfohomeubuntujobs
2条回答

关于通过systemd启动任务:

当run this way最初为空时,PATH变量有问题。也就是说,当您写入文件/etc/sysconfig/airlow时:

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

你真的写了:

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

因此,变量PATH不包含本地执行器用于运行任务的/bin实用程序。

所以我不明白为什么在这个文件中没有指定AIRFLOW_HOME。也就是说,气流在其中查找其配置文件的目录。

文件可能有日期?

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

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

以下是airflow webeserver --help输出(来自版本1.8):

-D, --daemon Daemonize instead of running in the foreground

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

万一airflow scheduler -D失败的快速提示:

这已经包含在评论中了,但这里似乎值得一提。运行气流计划程序时,它将创建文件$AIRFLOW_HOME/airflow-scheduler.pid。如果您尝试重新运行airflow scheduler守护进程,这几乎肯定会生成文件$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 

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

相关问题 更多 >