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

Commit e9326cf

Browse files
authored
Merge pull request #373 from jumpstarter-dev/monitor-expire
Stop the lease monitor after lease expiration
2 parents 428e212 + 7647525 commit e9326cf

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

  • packages/jumpstarter/jumpstarter/client

packages/jumpstarter/jumpstarter/client/lease.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,20 @@ async def monitor_async(self, threshold: timedelta = timedelta(minutes=5)):
163163
async def _monitor():
164164
while True:
165165
lease = await self.get()
166+
# TODO: use effective_end_time as the authoritative source for lease end time
166167
if lease.effective_begin_time:
167168
end_time = lease.effective_begin_time + lease.duration
168169
remain = end_time - datetime.now(tz=datetime.now().astimezone().tzinfo)
169-
if remain < threshold:
170+
if remain < timedelta(0):
171+
# lease already expired, stopping monitor
172+
logger.info("Lease {} ended at {}".format(self.name, end_time))
173+
break
174+
elif remain < threshold:
175+
# lease expiring soon, check again on expected expiration time in case it's extended
170176
logger.info("Lease {} ending soon in {} at {}".format(self.name, remain, end_time))
171177
await sleep(threshold.total_seconds())
172178
else:
179+
# lease still active, check again in 5 seconds
173180
await sleep(5)
174181
else:
175182
await sleep(1)

0 commit comments

Comments
 (0)