Skip to content
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

Fix CeleryKubernetesExecutor #16700

Merged
merged 1 commit into from Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions airflow/jobs/base_job.py
Expand Up @@ -25,6 +25,7 @@
from sqlalchemy.orm import backref, foreign, relationship
from sqlalchemy.orm.session import make_transient

from airflow.compat.functools import cached_property
from airflow.configuration import conf
from airflow.exceptions import AirflowException
from airflow.executors.executor_loader import ExecutorLoader
Expand Down Expand Up @@ -94,8 +95,11 @@ class BaseJob(Base, LoggingMixin):

def __init__(self, executor=None, heartrate=None, *args, **kwargs):
self.hostname = get_hostname()
self.executor = executor or ExecutorLoader.get_default_executor()
self.executor_class = self.executor.__class__.__name__
if executor:
self.executor = executor
self.executor_class = executor.__class__.__name__
else:
self.executor_class = conf.get('core', 'EXECUTOR')
self.start_date = timezone.utcnow()
self.latest_heartbeat = timezone.utcnow()
if heartrate is not None:
Expand All @@ -104,6 +108,10 @@ def __init__(self, executor=None, heartrate=None, *args, **kwargs):
self.max_tis_per_query = conf.getint('scheduler', 'max_tis_per_query')
super().__init__(*args, **kwargs)

@cached_property
def executor(self):
return ExecutorLoader.get_default_executor()

@classmethod
@provide_session
def most_recent_job(cls, session=None) -> Optional['BaseJob']:
Expand Down
7 changes: 6 additions & 1 deletion tests/jobs/test_base_job.py
Expand Up @@ -118,7 +118,12 @@ def test_heartbeat_failed(self, mock_create_session):

assert job.latest_heartbeat == when, "attribute not updated when heartbeat fails"

@conf_vars({('scheduler', 'max_tis_per_query'): '100'})
@conf_vars(
{
('scheduler', 'max_tis_per_query'): '100',
('core', 'executor'): 'SequentialExecutor',
}
)
@patch('airflow.jobs.base_job.ExecutorLoader.get_default_executor')
@patch('airflow.jobs.base_job.get_hostname')
@patch('airflow.jobs.base_job.getuser')
Expand Down