微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

气流DAGS正在运行,但任务未运行/正在排队-发送芹菜任务时出错:超时

如何解决气流DAGS正在运行,但任务未运行/正在排队-发送芹菜任务时出错:超时

我们让Airflow 1.10.3与Celery 4.1.1和Redis一起用作消息代理。

启动网络服务器时,预定的DAG会无限期进入运行状态,并且在Flower UI中看不到任何活动任务。

在日志(气流启动日志)中,我们收到以下错误:(发送芹菜任务时发生错误:超时

 {"timestamp":"2020-11-11T09:45:58.326682","hostname":"","process":"scheduler","name":"airflow.executors.celery_executor.CeleryExecutor","level":"ERROR","message":"Error sending Celery task:Timeout,PID: 16001\nCelery Task ID: ('tutorial','print_date',datetime.datetime(2020,11,9,tzinfo=<Timezone [UTC]>),1)\nTraceback (most recent call last):\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/kombu\/utils\/functional.py\",line 42,in __call__\n    return self.__value__\nAttributeError: 'ChannelPromise' object has no attribute '__value__'\n\nDuring handling of the above exception,another exception occurred:\n\nTraceback (most recent call last):\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/kombu\/transport\/virtual\/base.py\",line 921,in create_channel\n    return self._avail_channels.pop()\nIndexError: pop from empty list\n\nDuring handling of the above exception,another exception occurred:\n\nTraceback (most recent call last):\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/airflow\/executors\/celery_executor.py\",line 118,in send_task_to_executor\n    result = task.apply_async(args=[command],queue=queue)\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/celery\/app\/task.py\",line 535,in apply_async\n    **options\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/celery\/app\/base.py\",line 745,in send_task\n    amqp.send_task_message(P,name,message,**options)\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/celery\/app\/amqp.py\",line 552,in send_task_message\n    **properties\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/kombu\/messaging.py\",line 181,in publish\n    exchange_name,declare,\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/kombu\/connection.py\",line 518,in _ensured\n    return fun(*args,**kwargs)\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/kombu\/messaging.py\",line 187,in _publish\n    channel = self.channel\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/kombu\/messaging.py\",line 209,in _get_channel\n    channel = self._channel = channel()\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/kombu\/utils\/functional.py\",line 44,in __call__\n    value = self.__value__ = self.__contract__()\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/kombu\/messaging.py\",line 224,in <lambda>\n    channel = ChannelPromise(lambda: connection.default_channel)\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/kombu\/connection.py\",line 866,in default_channel\n    self.ensure_connection(**conn_opts)\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/kombu\/connection.py\",line 430,in ensure_connection\n    callback,timeout=timeout)\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/kombu\/utils\/functional.py\",line 343,in retry_over_time\n    return fun(*args,**kwargs)\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/kombu\/connection.py\",line 283,in connect\n    return self.connection\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/kombu\/connection.py\",line 837,in connection\n    self._connection = self._establish_connection()\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/kombu\/connection.py\",line 792,in _establish_connection\n    conn = self.transport.establish_connection()\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/kombu\/transport\/virtual\/base.py\",line 941,in establish_connection\n    self._avail_channels.append(self.create_channel(self))\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/kombu\/transport\/virtual\/base.py\",line 923,in create_channel\n    channel = self.Channel(connection)\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/kombu\/transport\/redis.py\",line 521,in __init__\n    self.client.ping()\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/redis\/client.py\",line 1351,in ping\n    return self.execute_command('PING')\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/redis\/client.py\",line 875,in execute_command\n    conn = self.connection or pool.get_connection(command_name,**options)\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/redis\/connection.py\",line 1185,in get_connection\n    connection.connect()\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/redis\/connection.py\",in connect\n    sock = self._connect()\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/redis\/connection.py\",line 845,in _connect\n    sock = super(SSLConnection,self)._connect()\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/redis\/connection.py\",line 579,in _connect\n    socket.soCK_STREAM):\n  File \"\/usr\/lib64\/python3.7\/socket.py\",line 748,in getaddrinfo\n    for res in _socket.getaddrinfo(host,port,family,type,proto,flags):\n  File \"\/usr\/local\/lib\/python3.7\/site-packages\/airflow\/utils\/timeout.py\",line 43,in handle_timeout\n    raise AirflowTasktimeout(self.error_message)\nairflow.exceptions.AirflowTasktimeout: Timeout,PID: 16001\n\n"} 

配置文件

[core]
# The home folder for airflow,default is ~/airflow
airflow_home = /home/ec2-user/airflow

# The folder where your airflow pipelines live,most likely a
# subfolder in a code repository
# This path must be absolute
dags_folder = /home/ec2-user/airflow/dags

# The folder where airflow should store its log files
# This path must be absolute
base_log_folder = /var/log/airflow

# Logging level
logging_level = DEBUG
fab_logging_level = WARN

# Logging class
# Specify the class that will specify the logging configuration
# This class has to be on the python classpath
# logging_config_class = my.path.default_local_settings.LOGGING_CONfig
logging_config_class = log_config.CUSTOM_LOGGING_CONfig

# Log format
# we need to escape the curly braces by adding an additional curly brace
log_format = [%%(asctime)s] {%%(filename)s:%%(lineno)d} %%(levelname)s - %%(message)s
simple_log_format = %%(asctime)s %%(levelname)s - %%(message)s

# Log filename format
# we need to escape the curly braces by adding an additional curly brace
log_filename_template = {{ ti.dag_id }}/{{ ti.task_id }}/{{ ts }}/{{ try_number }}.log
log_processor_filename_template = {{ filename }}.log

# Hostname by providing a path to a callable,which will resolve the hostname
hostname_callable = socket:getfqdn

# Default timezone in case supplied date times are naive
# can be utc (default),system,or any IANA timezone string (e.g. Europe/Amsterdam)
default_timezone = utc

# Airflow can store logs remotely in AWS S3 or Google Cloud Storage. Users
# must supply a remote location URL (starting with either 's3://...' or
# 'gs://...') and an Airflow connection id that provides access to the storage
# location.
remote_base_log_folder = 
remote_log_conn_id = 
# Use server-side encryption for logs stored in S3
encrypt_s3_logs = False
# DEPRECATED option for remote log storage,use remote_base_log_folder instead!
s3_log_folder = 

# The executor class that airflow should use. Choices include
# SequentialExecutor,LocalExecutor,CeleryExecutor
executor = CeleryExecutor
broker_url = redis://***************************************:6379/0
# The sqlAlchemy connection string to the Metadata database.
# sqlAlchemy supports many different database engine,more information
# their website
sql_alchemy_conn = MysqL://***************************************:3306/airflow

# The sqlAlchemy pool size is the maximum number of database connections
# in the pool.
sql_alchemy_pool_size = 5

# The sqlAlchemy pool recycle is the number of seconds a connection
# can be idle in the pool before it is invalidated. This config does
# not apply to sqlite.
sql_alchemy_pool_recycle = 2000

# The amount of parallelism as a setting to the executor. This defines
# the max number of task instances that should run simultaneously
# on this airflow installation
parallelism = 32

# The number of task instances allowed to run concurrently by the scheduler
dag_concurrency = 6

# Are DAGs paused by default at creation
dags_are_paused_at_creation = False

# When not using pools,tasks are run in the "default pool",# whose size is guided by this config element
non_pooled_task_slot_count = 128

# The maximum number of active DAG runs per DAG
max_active_runs_per_dag = 16

# Whether to load the examples that ship with Airflow. It's good to
# get started,but you probably want to set this to False in a production
# environment
load_examples = False

# Where your Airflow plugins are stored
plugins_folder = /home/ec2-user/airflow/plugins

# Secret key to save connection passwords in the db
fernet_key = 

# Whether to disable pickling dags
donot_pickle = False

# How long before timing out a python file import while filling the DagBag
dagbag_import_timeout = 30

# The class to use for running task instances in a subprocess
task_runner = BashTaskRunner

# If set,tasks without a `run_as_user` argument will be run with this user
# Can be used to de-elevate a sudo user running Airflow when executing tasks
default_impersonation = 

# What security module to use (for example kerberos):
security =

# Turn unit test mode on (overwrites many configuration options with test
# values at runtime)
unit_test_mode = False

# full path of dag_processor_manager logfile
dag_processor_manager_log_location = /var/log/airflow/dag_processor_manager/dag_processor_manager.log

# Name of handler to read task instance logs.
# Default to use task handler.
task_log_reader = task

# Whether to enable pickling for xcom (note that this is insecure and allows for
# RCE exploits). This will be deprecated in Airflow 2.0 (be forced to False).
enable_xcom_pickling = True

# When a task is killed forcefully,this is the amount of time in seconds that
# it has to cleanup after it is sent a SIGTERM,before it is SIGKILLED
killed_task_cleanup_time = 60

# Whether to override params with dag_run.conf. If you pass some key-value pairs through `airflow backfill -c` or
# `airflow trigger_dag -c`,the key-value pairs will override the existing ones in params.
dag_run_conf_overrides_params = False

[cli]
# In what way should the cli access the API. The LocalClient will use the
# database directly,while the json_client will use the api running on the
# webserver
api_client = airflow.api.client.local_client
##endpoint_url = http://localhost:8080
endpoint_url = 10.136.119.91

[api]
# How to authenticate users of the API
#auth_backend = airflow.api.auth.backend.default

[lineage]
# what lineage backend to use
#backend = 

[atlas]
sasl_enabled = False
host = 
port = 21000
username = 
password = 

[operators]
# The default owner assigned to each new operator,unless
# provided explicitly or passed via `default_args`
default_owner = Airflow
default_cpus = 1
default_ram = 512
default_disk = 512
default_gpus = 0

[webserver]
# The base url of your website as airflow cannot guess what domain or
# cname you are using. This is used in automated emails that
# airflow sends to point links to the right web server
#base_url =

# The ip specified when starting the web server
web_server_host = 0.0.0.0

# The port on which to run the web server
web_server_port = 8080

# Paths to the SSL certificate and key for the web server. When both are
# provided SSL will be enabled. This does not change the web server port.
web_server_ssl_cert = /etc/ssl/certs/airflow-selfsigned.crt
web_server_ssl_key = /etc/ssl/private/airflow-selfsigned.key

# Number of seconds the webserver waits before killing gunicorn master that doesn't respond
web_server_master_timeout = 1200

# Number of seconds the gunicorn webserver waits before timing out on a worker
web_server_worker_timeout = 1200

# Number of workers to refresh at a time. When set to 0,worker refresh is
# disabled. When nonzero,airflow periodically refreshes webserver workers by
# bringing up new ones and killing old ones.
worker_refresh_batch_size = 1

# Number of seconds to wait before refreshing a batch of workers.
worker_refresh_interval = 30

# Secret key used to run your flask app
secret_key = temporary_key

# Number of workers to run the Gunicorn web server
workers = 4

# The worker class gunicorn should use. Choices include
# sync (default),eventlet,gevent
worker_class = sync

# Log files for the gunicorn webserver. '-' means log to stderr.
access_logfile = /var/log/airflow/gunicorn-access.log
error_logfile = /var/log/airflow/gunicorn-error.log

# Expose the configuration file in the web server
expose_config = False

# Set to true to turn on authentication:
# http://pythonhosted.org/airflow/security.html#web-authentication
authenticate = True
auth_backend = airflow.contrib.auth.backends.password_auth

# Filter the list of dags by owner name (requires authentication to be enabled)
filter_by_owner = False

# Filtering mode. Choices include user (default) and ldapgroup.
# Ldap group filtering requires using the ldap backend
#
# Note that the ldap server needs the "memberOf" overlay to be set up
# in order to user the ldapgroup mode.
owner_mode = user

# Default DAG orientation. Valid values are:
# LR (Left->Right),TB (Top->Bottom),RL (Right->Left),BT (Bottom->Top)
dag_orientation = LR

# Puts the webserver in demonstration mode; blurs the names of Operators for
# privacy.
demo_mode = False

# The amount of time (in secs) webserver will wait for initial handshake
# while fetching logs from other worker machine
log_fetch_timeout_sec = 5

# By default,the webserver shows paused DAGs. Flip this to hide paused
# DAGs by default
hide_paused_dags_by_default = False

# Consistent page size across all listing views in the UI
page_size = 100

# Use FAB-based webserver with RBAC feature
rbac = True

# Define the color of navigation bar
navbar_color = #007A87

# Default dagrun to show in UI
default_dag_run_display_number = 25

[email]
email_backend = airflow.utils.email.send_email_smtp

[smtp]
# If you want airflow to send emails on retries,failure,and you want to use
# the airflow.utils.email.send_email_smtp function,you have to configure an
# smtp server here
smtp_host = localhost
smtp_starttls = True
smtp_ssl = False
smtp_port = 25
smtp_mail_from = 

[celery]
# This section only applies if you are using the CeleryExecutor in
# [core] section above

# The app name that will be used by celery
celery_app_name = airflow.executors.celery_executor

# The concurrency that will be used when starting workers with the
# "airflow worker" command. This defines the number of task instances that
# a worker will take,so size up your workers based on the resources on
# your worker Box and the nature of your tasks
worker_concurrency = 16

# When you start an airflow worker,airflow starts a tiny web server
# subprocess to serve the workers local log files to the airflow main
# web server,who then builds pages and sends them to users. This defines
# the port on which the logs are served. It needs to be unused,and open
# visible from the main web server to connect into the workers.
worker_log_server_port = 8793

# The Celery broker URL. Celery supports RabbitMQ,Redis and experimentally
# a sqlalchemy database. Refer to the Celery documentation for more
# information.
broker_url = redis://***************************************:6379/0
celery_result_backend = db+MysqL://***************************************:3306/airflow
# Another key Celery setting
result_backend = db+MysqL://***************************************:3306/airflow

# Celery Flower is a sweet UI for Celery. Airflow has a shortcut to start
# it `airflow flower`. This defines the IP that Celery Flower runs on
flower_host = 0.0.0.0

# This defines the port that Celery Flower runs on
flower_port = 8443

# Default queue that tasks get assigned to and that worker listen on.
default_queue = default

# Import path for celery configuration options
celery_config_options = airflow.config_templates.default_celery.DEFAULT_CELERY_CONfig

# In case of using SSL
ssl_active = True
ssl_key = /etc/ssl/private/airflow-selfsigned.key
ssl_cert = /etc/ssl/certs/airflow-selfsigned.crt
ssl_cacert = 

[celery_broker_transport_options]
# This section is for specifying options which can be passed to the
# underlying celery broker transport.  See:
# http://docs.celeryproject.org/en/latest/userguide/configuration.html#std:setting-broker_transport_options

# The visibility timeout defines the number of seconds to wait for the worker
# to ackNowledge the task before the message is redelivered to another worker.
# Make sure to increase the visibility timeout to match the time of the longest
# ETA you're planning to use.
#
# visibility_timeout is only supported for Redis and SQS celery brokers.
# See:
#   http://docs.celeryproject.org/en/master/userguide/configuration.html#std:setting-broker_transport_options
#
#visibility_timeout = 21600
[scheduler]
# Task instances listen for external kill signal (when you clear tasks
# from the CLI or the UI),this defines the frequency at which they should
# listen (in seconds).
job_heartbeat_sec = 5

# The scheduler constantly tries to trigger new tasks (look at the
# scheduler section in the docs for more information). This defines
# how often the scheduler should run (in seconds).
scheduler_heartbeat_sec = 5

# after how much time should the scheduler terminate in seconds
# -1 indicates to run continuously (see also num_runs)
run_duration = -1

# after how much time a new DAGs should be picked up from the filesystem
min_file_process_interval = 0

# How many seconds to wait between file-parsing loops to prevent the logs from being spammed.
min_file_parsing_loop_time = 1

dag_dir_list_interval = 300

# How often should stats be printed to the logs
print_stats_interval = 30

child_process_log_directory = /var/log/airflow/scheduler

# Local task jobs periodically heartbeat to the DB. If the job has
# not heartbeat in this many seconds,the scheduler will mark the
# associated task instance as Failed and will re-schedule the task.
scheduler_zombie_task_threshold = 300

# Turn off scheduler catchup by setting this to False.
# Default behavior is unchanged and
# Command Line Backfills still work,but the scheduler
# will not do scheduler catchup if this is False,# however it can be set on a per DAG basis in the
# DAG deFinition (catchup)
catchup_by_default = True

# This changes the batch size of queries in the scheduling main loop.
# If this is too high,sql query performance may be impacted by one
# or more of the following:
#  - reversion to full table scan
#  - complexity of query predicate
#  - excessive locking
#
# Additionally,you may hit the maximum allowable query length for your db.
#
# Set this to 0 for no limit (not advised)
max_tis_per_query = 512

# Statsd (https://github.com/etsy/statsd) integration settings
statsd_on = True
statsd_host = localhost
statsd_port = 8125
statsd_prefix = airflow

# The scheduler can run multiple threads in parallel to schedule dags.
# This defines how many threads will run. However airflow will never
# use more threads than the amount of cpu cores available.
max_threads = 4

authenticate = False

[mesos]
# Mesos master address which MesosExecutor will connect to.
master = localhost:5050

# The framework name which Airflow scheduler will register itself as on mesos
framework_name = Airflow

# Number of cpu cores required for running one task instance using
# 'airflow run <dag_id> <task_id> <execution_date> --local -p <pickle_id>'
# command on a mesos slave
task_cpu = 1

# Memory in MB required for running one task instance using
# 'airflow run <dag_id> <task_id> <execution_date> --local -p <pickle_id>'
# command on a mesos slave
task_memory = 256

# Enable framework checkpointing for mesos
# See http://mesos.apache.org/documentation/latest/slave-recovery/
checkpoint = False

# Failover timeout in milliseconds.
# When checkpointing is enabled and this option is set,Mesos waits
# until the configured timeout for
# the MesosExecutor framework to re-register after a failover. Mesos
# shuts down running tasks if the
# MesosExecutor framework fails to re-register within this timeframe.
# failover_timeout = 604800

# Enable framework authentication for mesos
# See http://mesos.apache.org/documentation/latest/configuration/
authenticate = False

# Mesos credentials,if authentication is enabled
# default_principal = admin
# default_secret = admin

[admin]
# UI to hide sensitive variable fields when set to True
hide_sensitive_variable_fields = True


可以请你帮忙

解决方法

1-通常您的 celery 错误日志将在您的调度程序日志中可用,因此最好在那里检查它。 如果您没有将它作为守护进程或后台进程运行,您可以在终端中详细查看问题到底是什么。

2-当我快速查看它(您的配置)时,它看起来很像默认配置文件或几乎与在线安装指南匹配的配置 ==> 所以它一定没有大问题.

3- 您的错误尚不清楚,但我相信如果您刚刚运送了您的 dag 并且在此之后突然出现错误,您很可能会遇到您的经纪人许可错误或任何相关错误,因为 celery 将与它。所以我将提供一个常见问题的通用解决方案希望它对社区有所帮助,因为您已经过去 3 个月了:)

rabbitmqctl set_permissions -p /myvhost guest ".*" ".*" ".*"

guest = 您的用户(您作为经纪人提供的(在本例中为 RabbitMQ)用户)

/myvhost = 对你来说它可能只是斜线或 /

祝你好运。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。