Skip to content

Commit 11ffa51

Browse files
committed
Fix start/stop buttons on web broken by faster start/stop patch
In past versions, startProcess() and stopProcess() would always return a callback. 50d1857 changed this so they may return either a callback or a bool, but the web interface was not updated.
1 parent 4306528 commit 11ffa51

File tree

1 file changed

+47
-33
lines changed

1 file changed

+47
-33
lines changed

supervisor/web.py

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,9 @@ def wrong():
336336

337337
if action == 'start':
338338
try:
339-
callback = rpcinterface.supervisor.startProcess(
340-
namespec)
339+
bool_or_callback = (
340+
rpcinterface.supervisor.startProcess(namespec)
341+
)
341342
except RPCError as e:
342343
if e.code == Faults.NO_FILE:
343344
msg = 'no such file'
@@ -357,47 +358,60 @@ def starterr():
357358
starterr.delay = 0.05
358359
return starterr
359360

360-
def startprocess():
361-
try:
362-
result = callback()
363-
except RPCError as e:
364-
if e.code == Faults.SPAWN_ERROR:
365-
msg = 'spawn error'
366-
elif e.code == Faults.ABNORMAL_TERMINATION:
367-
msg = 'abnormal termination'
368-
else:
369-
msg = 'unexpected rpc fault [%d] %s' % (
370-
e.code, e.text)
371-
return 'ERROR: Process %s: %s' % (namespec, msg)
372-
373-
if result is NOT_DONE_YET:
374-
return NOT_DONE_YET
375-
return 'Process %s started' % namespec
376-
startprocess.delay = 0.05
377-
return startprocess
361+
if callable(bool_or_callback):
362+
def startprocess():
363+
try:
364+
result = bool_or_callback()
365+
except RPCError as e:
366+
if e.code == Faults.SPAWN_ERROR:
367+
msg = 'spawn error'
368+
elif e.code == Faults.ABNORMAL_TERMINATION:
369+
msg = 'abnormal termination'
370+
else:
371+
msg = 'unexpected rpc fault [%d] %s' % (
372+
e.code, e.text)
373+
return 'ERROR: Process %s: %s' % (namespec, msg)
374+
375+
if result is NOT_DONE_YET:
376+
return NOT_DONE_YET
377+
return 'Process %s started' % namespec
378+
startprocess.delay = 0.05
379+
return startprocess
380+
else:
381+
def startdone():
382+
return 'Process %s started' % namespec
383+
startdone.delay = 0.05
384+
return startdone
378385

379386
elif action == 'stop':
380387
try:
381-
callback = rpcinterface.supervisor.stopProcess(
382-
namespec)
388+
bool_or_callback = (
389+
rpcinterface.supervisor.stopProcess(namespec)
390+
)
383391
except RPCError as e:
384392
def stoperr():
385393
return 'unexpected rpc fault [%d] %s' % (
386394
e.code, e.text)
387395
stoperr.delay = 0.05
388396
return stoperr
389397

390-
def stopprocess():
391-
try:
392-
result = callback()
393-
except RPCError as e:
394-
return 'unexpected rpc fault [%d] %s' % (
395-
e.code, e.text)
396-
if result is NOT_DONE_YET:
397-
return NOT_DONE_YET
398-
return 'Process %s stopped' % namespec
399-
stopprocess.delay = 0.05
400-
return stopprocess
398+
if callable(bool_or_callback):
399+
def stopprocess():
400+
try:
401+
result = bool_or_callback()
402+
except RPCError as e:
403+
return 'unexpected rpc fault [%d] %s' % (
404+
e.code, e.text)
405+
if result is NOT_DONE_YET:
406+
return NOT_DONE_YET
407+
return 'Process %s stopped' % namespec
408+
stopprocess.delay = 0.05
409+
return stopprocess
410+
else:
411+
def stopdone():
412+
return 'Process %s stopped' % namespec
413+
stopdone.delay = 0.05
414+
return stopdone
401415

402416
elif action == 'restart':
403417
callback = rpcinterface.system.multicall(

0 commit comments

Comments
 (0)