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


##########
airflow/jobs/job.py:
##########
@@ -117,6 +115,15 @@ def __init__(self, executor=None, heartrate=None, 
**kwargs):
     def executor(self):
         return ExecutorLoader.get_default_executor()
 
+    @cached_property
+    def heartrate(self):
+        if self.job_type == "TriggererJob":
+            return conf.getfloat("triggerer", "JOB_HEARTBEAT_SEC")
+        else:
+            # Heartrate used to be hardcoded to scheduler, so in all other
+            # cases continue to use that value for back compat
+            return conf.getfloat("scheduler", "JOB_HEARTBEAT_SEC")

Review Comment:
   Actually this is ok accordig to how `cached_property` works. I recently 
stumbled upon that.
   
   The `@cached_property` works different than `@property` -> it actually 
creates an attribute that is set the first time the property is used and you 
can freely delete or assign the attribute a different value. This is a nice 
one, because you can even invalidate the cache by simply deleting the attribute 
(which is for example very cool for testing and I am already using it to 
invalidat sensitive field list when loading provider configuration 
https://github.com/apache/airflow/blob/main/airflow/configuration.py#L1854
   
   It was working like that since 3.8 but it made it into "official part of the 
API" in Python 3.9. Similarly as HashMap ordering graduated from being 
implementation detail to official behaviour.



-- 
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