You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/04/20 04:50:17 UTC

[GitHub] [airflow] milton0825 commented on a change in pull request #5127: [AIRFLOW-4343] Show warning in UI if scheduler is not running

milton0825 commented on a change in pull request #5127: [AIRFLOW-4343] Show warning in UI if scheduler is not running
URL: https://github.com/apache/airflow/pull/5127#discussion_r277123855
 
 

 ##########
 File path: airflow/jobs.py
 ##########
 @@ -98,25 +98,48 @@ class BaseJob(Base, LoggingMixin):
         Index('idx_job_state_heartbeat', state, latest_heartbeat),
     )
 
+    heartrate = conf.getfloat('scheduler', 'JOB_HEARTBEAT_SEC'),
+
     def __init__(
             self,
             executor=executors.get_default_executor(),
-            heartrate=conf.getfloat('scheduler', 'JOB_HEARTBEAT_SEC'),
+            heartrate=None,
             *args, **kwargs):
         self.hostname = get_hostname()
         self.executor = executor
         self.executor_class = executor.__class__.__name__
         self.start_date = timezone.utcnow()
         self.latest_heartbeat = timezone.utcnow()
-        self.heartrate = heartrate
+        if heartrate is not None:
+            self.heartrate = heartrate
         self.unixname = getpass.getuser()
         self.max_tis_per_query = conf.getint('scheduler', 'max_tis_per_query')
         super(BaseJob, self).__init__(*args, **kwargs)
 
-    def is_alive(self):
+    @classmethod
+    @provide_session
+    def most_recent_job(cls, session):  # type: (Session) -> Optional[BaseJob]
+        """
+        Return the most recent job of this type, if any, based on last
+        heartbeat received.
+
+        This method should be called on a subclass (i.e. on SchedulerJob) to
+        return jobs of that type.
+
+        :rtype: BaseJob or None
+        """
+        return session.query(cls).order_by(cls.latest_heartbeat.desc()).limit(1).first()
+
+    def is_alive(self, grace_multiplier=2.1):
+        """
+        Is this job currently alive.
+
+        We define alive as in a state of RUNNING, and within a multiple of the
+        heartrate (default of 2.1)
 
 Review comment:
   +1 on an explanation on why `2.1` is chosen as default

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services