You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "ephraimbuddy (via GitHub)" <gi...@apache.org> on 2023/04/11 13:31:21 UTC
[GitHub] [airflow] ephraimbuddy commented on a diff in pull request #30376: Remove JobRunners back reference from Job
ephraimbuddy commented on code in PR #30376:
URL: https://github.com/apache/airflow/pull/30376#discussion_r1162738450
##########
airflow/jobs/job.py:
##########
@@ -156,7 +152,10 @@ def kill(self, session: Session = NEW_SESSION) -> NoReturn:
def on_kill(self):
"""Will be called when an external kill command is received."""
- def heartbeat(self, only_if_necessary: bool = False) -> None:
+ @provide_session
+ def heartbeat(
+ self, heartbeat_callback: Callable[[SASession], None], session: Session = NEW_SESSION
Review Comment:
```suggestion
self, heartbeat_callback: Callable[[Session], None], session: Session = NEW_SESSION
```
Won't `Session` from orm.session serve?
##########
tests/cli/commands/test_jobs_command.py:
##########
@@ -75,52 +78,64 @@ def test_should_report_success_for_one_working_scheduler_with_hostname(self):
def test_should_report_success_for_ha_schedulers(self):
scheduler_jobs = []
+ job_runners = []
with create_session() as session:
for _ in range(3):
- scheduler_job = Job(job_runner=SchedulerJobRunner())
+ scheduler_job = Job()
+ job_runner = SchedulerJobRunner(job=scheduler_job)
scheduler_job.state = State.RUNNING
session.add(scheduler_job)
scheduler_jobs.append(scheduler_job)
+ job_runners.append(job_runner)
session.commit()
- scheduler_job.heartbeat()
-
- with contextlib.redirect_stdout(io.StringIO()) as temp_stdout:
- jobs_command.check(
- self.parser.parse_args(
- ["jobs", "check", "--job-type", "SchedulerJob", "--limit", "100", "--allow-multiple"]
+ scheduler_job.heartbeat(heartbeat_callback=job_runner.heartbeat_callback)
+ try:
+ with contextlib.redirect_stdout(io.StringIO()) as temp_stdout:
+ jobs_command.check(
+ self.parser.parse_args(
+ ["jobs", "check", "--job-type", "SchedulerJob", "--limit", "100", "--allow-multiple"]
+ )
)
- )
- assert "Found 3 alive jobs." in temp_stdout.getvalue()
- for scheduler_job in scheduler_jobs:
- if scheduler_job.job_runner.processor_agent:
- scheduler_job.job_runner.processor_agent.end()
+ assert "Found 3 alive jobs." in temp_stdout.getvalue()
+ finally:
Review Comment:
nit: do we need the try/finally clause?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org