Skip to content

Commit 0137efe

Browse files
committed
refactor: update startretries logic for readability
1 parent 98e7f59 commit 0137efe

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

supervisor/process.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,12 @@ def transition(self):
677677
# STOPPED -> STARTING
678678
self.spawn()
679679
elif state == ProcessStates.BACKOFF:
680-
if self.backoff <= self.config.startretries or self.config.startretries == -1:
681-
if now > self.delay or self.config.startretries == -1:
680+
# immediate retry on startretries set to -1
681+
if self.config.startretries == -1:
682+
# BACKOFF -> STARTING
683+
self.spawn()
684+
if self.backoff <= self.config.startretries:
685+
if now > self.delay:
682686
# BACKOFF -> STARTING
683687
self.spawn()
684688

@@ -698,13 +702,18 @@ def transition(self):
698702
logger.info('success: %s %s' % (processname, msg))
699703

700704
if state == ProcessStates.BACKOFF:
701-
if self.backoff > self.config.startretries and self.config.startretries != -1:
702-
# BACKOFF -> FATAL if the proc has exceeded its number
703-
# of retries
704-
self.give_up()
705-
msg = ('entered FATAL state, too many start retries too '
706-
'quickly')
707-
logger.info('gave up: %s %s' % (processname, msg))
705+
# never give up if startretries set to -1 - otherwise
706+
# check whether backoff exceeded the configured startretries.
707+
if self.config.startretries == -1:
708+
pass
709+
else:
710+
if self.backoff > self.config.startretries:
711+
# BACKOFF -> FATAL if the proc has exceeded its number
712+
# of retries
713+
self.give_up()
714+
msg = ('entered FATAL state, too many start retries too '
715+
'quickly')
716+
logger.info('gave up: %s %s' % (processname, msg))
708717

709718
elif state == ProcessStates.STOPPING:
710719
time_left = self.delay - now

0 commit comments

Comments
 (0)