Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit 6c4d2df

Browse files
improve client's lease monitoring
we monitor lease status too frequently (every 5s) which doesn't correspond to the default grpc keepalive which we just made longer. Let's lighten the load a bit and poll less frequent, once in 30s. Changed the info message about lease expiring son to more friendly "ending in 5 minutes". Also, once controller starts providing end time this will use the controller's timestamp. Until then fall back to the locally calculated begin time + duration.
1 parent 39131d7 commit 6c4d2df

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

  • packages/jumpstarter/jumpstarter/client

packages/jumpstarter/jumpstarter/client/lease.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,23 +248,25 @@ async def _wait_for_ready_connection(self, path: str):
248248
@asynccontextmanager
249249
async def monitor_async(self, threshold: timedelta = timedelta(minutes=5)):
250250
async def _monitor():
251+
check_interval = 30 # seconds - check periodically for external lease changes
251252
while True:
252253
lease = await self.get()
253-
# TODO: use effective_end_time as the authoritative source for lease end time
254254
if lease.effective_begin_time:
255-
end_time = lease.effective_begin_time + lease.duration
255+
# Calculate end time from effective_end_time or fallback to begin_time + duration
256+
end_time = lease.effective_end_time
257+
if not end_time or end_time.timestamp() == 0:
258+
end_time = lease.effective_begin_time + lease.duration
259+
256260
remain = end_time - datetime.now(tz=datetime.now().astimezone().tzinfo)
257261
if remain < timedelta(0):
258262
# lease already expired, stopping monitor
259263
logger.info("Lease {} ended at {}".format(self.name, end_time))
260264
break
261-
elif remain < threshold:
262-
# lease expiring soon, check again on expected expiration time in case it's extended
263-
logger.info("Lease {} ending soon in {} at {}".format(self.name, remain, end_time))
264-
await sleep(threshold.total_seconds())
265-
else:
266-
# lease still active, check again in 5 seconds
267-
await sleep(5)
265+
# Log once when entering the threshold window
266+
if threshold - timedelta(seconds=check_interval) <= remain < threshold:
267+
logger.info("Lease {} ending in {} minutes at {}".format(
268+
self.name, int((remain.total_seconds() + 30) // 60), end_time))
269+
await sleep(min(remain.total_seconds(), check_interval))
268270
else:
269271
await sleep(1)
270272

0 commit comments

Comments
 (0)