potiuk commented on code in PR #34026:
URL: https://github.com/apache/airflow/pull/34026#discussion_r1315220044


##########
airflow/jobs/job.py:
##########
@@ -137,28 +134,23 @@ def is_alive(self, grace_multiplier=2.1):
         :param grace_multiplier: multiplier of heartrate to require heart beat
             within
         """
-        if self.job_type == "SchedulerJob":
-            health_check_threshold: int = conf.getint("scheduler", 
"scheduler_health_check_threshold")
-        elif self.job_type == "TriggererJob":
-            health_check_threshold: int = conf.getint("triggerer", 
"triggerer_health_check_threshold")
-        else:
-            health_check_threshold: int = self.heartrate * grace_multiplier
-        return (
-            self.state == JobState.RUNNING
-            and (timezone.utcnow() - self.latest_heartbeat).total_seconds() < 
health_check_threshold
+        return Job._is_alive(
+            job_type=self.job_type,
+            heartrate=self.heartrate,
+            state=self.state,
+            latest_heartbeat=self.latest_heartbeat,
+            grace_multiplier=grace_multiplier,
         )
 
     @provide_session
     def kill(self, session: Session = NEW_SESSION) -> NoReturn:
         """Handle on_kill callback and updates state in database."""
-        job = session.scalar(select(Job).where(Job.id == self.id).limit(1))
-        job.end_date = timezone.utcnow()
         try:
             self.on_kill()
         except Exception as e:
             self.log.error("on_kill() method failed: %s", e)
-        session.merge(job)
-        session.commit()
+
+        Job._kill(job_id=self.id, session=session)

Review Comment:
   This is slight change in the semantics - job end_date is updated after the 
on_kill, but looking at implementations, that des not matter.



##########
airflow/jobs/job.py:
##########
@@ -137,28 +134,23 @@ def is_alive(self, grace_multiplier=2.1):
         :param grace_multiplier: multiplier of heartrate to require heart beat
             within
         """
-        if self.job_type == "SchedulerJob":
-            health_check_threshold: int = conf.getint("scheduler", 
"scheduler_health_check_threshold")
-        elif self.job_type == "TriggererJob":
-            health_check_threshold: int = conf.getint("triggerer", 
"triggerer_health_check_threshold")
-        else:
-            health_check_threshold: int = self.heartrate * grace_multiplier
-        return (
-            self.state == JobState.RUNNING
-            and (timezone.utcnow() - self.latest_heartbeat).total_seconds() < 
health_check_threshold
+        return Job._is_alive(
+            job_type=self.job_type,
+            heartrate=self.heartrate,
+            state=self.state,
+            latest_heartbeat=self.latest_heartbeat,
+            grace_multiplier=grace_multiplier,
         )
 
     @provide_session
     def kill(self, session: Session = NEW_SESSION) -> NoReturn:
         """Handle on_kill callback and updates state in database."""
-        job = session.scalar(select(Job).where(Job.id == self.id).limit(1))
-        job.end_date = timezone.utcnow()
         try:
             self.on_kill()
         except Exception as e:
             self.log.error("on_kill() method failed: %s", e)
-        session.merge(job)
-        session.commit()
+
+        Job._kill(job_id=self.id, session=session)

Review Comment:
   This is slight change in the semantics - job end_date is updated after the 
on_kill, but looking at implementations, that does not matter.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to