Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add maxbackoff and backoffincrement options #1626

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions supervisor/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,8 @@ def get(section, opt, *args, **kwargs):
autorestart = auto_restart(get(section, 'autorestart', 'unexpected'))
startsecs = integer(get(section, 'startsecs', 1))
startretries = integer(get(section, 'startretries', 3))
maxbackoff = integer(get(section, 'maxbackoff', 0))
backoffincrement = integer(get(section, 'backoffincrement', 1))
stopsignal = signal_number(get(section, 'stopsignal', 'TERM'))
stopwaitsecs = integer(get(section, 'stopwaitsecs', 10))
stopasgroup = boolean(get(section, 'stopasgroup', 'false'))
Expand Down Expand Up @@ -1041,6 +1043,8 @@ def get(section, opt, *args, **kwargs):
autorestart=autorestart,
startsecs=startsecs,
startretries=startretries,
maxbackoff=maxbackoff,
backoffincrement=backoffincrement,
uid=uid,
stdout_logfile=logfiles['stdout_logfile'],
stdout_capture_maxbytes = stdout_cmaxbytes,
Expand Down Expand Up @@ -1870,6 +1874,7 @@ class ProcessConfig(Config):
req_param_names = [
'name', 'uid', 'command', 'directory', 'umask', 'priority',
'autostart', 'autorestart', 'startsecs', 'startretries',
'maxbackoff', 'backoffincrement',
'stdout_logfile', 'stdout_capture_maxbytes',
'stdout_events_enabled', 'stdout_syslog',
'stdout_logfile_backups', 'stdout_logfile_maxbytes',
Expand Down
3 changes: 2 additions & 1 deletion supervisor/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ def change_state(self, new_state, expected=True):
self.state = new_state
if new_state == ProcessStates.BACKOFF:
now = time.time()
self.backoff += 1
if self.backoff < self.config.maxbackoff or self.config.maxbackoff == 0:
self.backoff += self.config.backoffincrement

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cdelguercio to prevent the issue you mentioned in #1626 (comment) you can use min:

self.backoff = min(self.backoff + self.config.backoffincrement, self.config.maxbackoff)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'd have to do something like:

self.backoff = self.config.maxbackoff == 0 ? self.backoff + self.config.backoffincrement : min(self.backoff + self.config.backoffincrement, self.config.maxbackoff);

The question is: what's preferred?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I see what you are saying, I missed the self.config.maxbackoff == 0 case.

What you have suggested looks correct 👍

self.delay = now + self.backoff

event_class = self.event_map.get(new_state)
Expand Down
3 changes: 3 additions & 0 deletions supervisor/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ class DummyPConfig:
def __init__(self, options, name, command, directory=None, umask=None,
priority=999, autostart=True,
autorestart=True, startsecs=10, startretries=999,
maxbackoff=0, backoffincrement=1,
uid=None, stdout_logfile=None, stdout_capture_maxbytes=0,
stdout_events_enabled=False,
stdout_logfile_backups=0, stdout_logfile_maxbytes=0,
Expand All @@ -526,6 +527,8 @@ def __init__(self, options, name, command, directory=None, umask=None,
self.autorestart = autorestart
self.startsecs = startsecs
self.startretries = startretries
self.maxbackoff = maxbackoff
self.backoffincrement = backoffincrement
self.uid = uid
self.stdout_logfile = stdout_logfile
self.stdout_capture_maxbytes = stdout_capture_maxbytes
Expand Down
3 changes: 3 additions & 0 deletions supervisor/tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -3419,6 +3419,7 @@ def _makeOne(self, *arg, **kw):
for name in ('name', 'command', 'directory', 'umask',
'priority', 'autostart', 'autorestart',
'startsecs', 'startretries', 'uid',
'maxbackoff', 'backoffincrement',
'stdout_logfile', 'stdout_capture_maxbytes',
'stdout_events_enabled', 'stdout_syslog',
'stderr_logfile', 'stderr_capture_maxbytes',
Expand Down Expand Up @@ -3517,6 +3518,7 @@ def _makeOne(self, *arg, **kw):
for name in ('name', 'command', 'directory', 'umask',
'priority', 'autostart', 'autorestart',
'startsecs', 'startretries', 'uid',
'maxbackoff', 'backoffincrement',
'stdout_logfile', 'stdout_capture_maxbytes',
'stdout_events_enabled', 'stdout_syslog',
'stderr_logfile', 'stderr_capture_maxbytes',
Expand Down Expand Up @@ -3565,6 +3567,7 @@ def _makeOne(self, *arg, **kw):
for name in ('name', 'command', 'directory', 'umask',
'priority', 'autostart', 'autorestart',
'startsecs', 'startretries', 'uid',
'maxbackoff', 'backoffincrement',
'stdout_logfile', 'stdout_capture_maxbytes',
'stdout_events_enabled', 'stdout_syslog',
'stderr_logfile', 'stderr_capture_maxbytes',
Expand Down
2 changes: 2 additions & 0 deletions supervisor/tests/test_supervisord.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ def make_pconfig(name, command, **params):
'name': name, 'command': command,
'directory': None, 'umask': None, 'priority': 999, 'autostart': True,
'autorestart': True, 'startsecs': 10, 'startretries': 999,
'maxbackoff': 0, 'backoffincrement': 1,
'uid': None, 'stdout_logfile': None, 'stdout_capture_maxbytes': 0,
'stdout_events_enabled': False,
'stdout_logfile_backups': 0, 'stdout_logfile_maxbytes': 0,
Expand Down Expand Up @@ -446,6 +447,7 @@ def make_pconfig(name, command, **params):
'name': name, 'command': command,
'directory': None, 'umask': None, 'priority': 999, 'autostart': True,
'autorestart': True, 'startsecs': 10, 'startretries': 999,
'maxbackoff': 0, 'backoffincrement': 1,
'uid': None, 'stdout_logfile': None, 'stdout_capture_maxbytes': 0,
'stdout_events_enabled': False,
'stdout_logfile_backups': 0, 'stdout_logfile_maxbytes': 0,
Expand Down
Loading