-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Catch arbitrary exception from run_job to prevent zombie scheduler #32707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
90db577
fc2db7b
2c4128c
6897d23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| """Scheduler command.""" | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| import signal | ||
| from contextlib import contextmanager | ||
| from multiprocessing import Process | ||
|
|
@@ -35,12 +36,17 @@ | |
| from airflow.utils.providers_configuration_loader import providers_configuration_loaded | ||
| from airflow.utils.scheduler_health import serve_health_check | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def _run_scheduler_job(job_runner: SchedulerJobRunner, *, skip_serve_logs: bool) -> None: | ||
| InternalApiConfig.force_database_direct_access() | ||
| enable_health_check = conf.getboolean("scheduler", "ENABLE_HEALTH_CHECK") | ||
| with _serve_logs(skip_serve_logs), _serve_health_check(enable_health_check): | ||
| run_job(job=job_runner.job, execute_callable=job_runner._execute) | ||
| try: | ||
| run_job(job=job_runner.job, execute_callable=job_runner._execute) | ||
| except Exception: | ||
| log.exception("Exception when running scheduler job") | ||
|
||
|
|
||
|
|
||
| @cli_utils.action_cli | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this? Usually I see it's called logger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please point to where the logger is named
logger? The modules I've touched so far all named logger aslogexampleUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. The example you shared is using
self.logand notlog. I believe this comes from extending the LoggingMixin class which has the log property.What I meant is in general when using
logging.getLogger(__name__), python modules call it asloggeracross the projects I have seen in so far. One example in our project I could find is hereairflow/airflow/utils/log/file_task_handler.py
Line 46 in 73b90c4
But I think I have another suggestion here. Since this is a CLI command I guess we could maybe use the AirflowConsole here to print the message? e.g. https://github.com/apache/airflow/blob/main/airflow/cli/commands/connection_command.py#L360
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming variables one way or another seems ultimately trivial, so I am perfectly okay with changing the variable name to
logger.On the other hand, I am not sure about using
AirflowConsolefor logging purposes. The code changes are located under theclimodule, but they are ultimately meant to catch exceptions that came up within the inner logic of the scheduler, so I think it should be treated like a normal logger.Another situation where I think using a logger is more appropriate is when the scheduler is run as a daemon (with
airflow scheduler -D), in which case using theAirflowConsolewill not log the exception.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming on this is unfortunately pretty inconsistent in Airflow. Personally I much prefer
loggerbut 🤷