Skip to content

Instantly share code, notes, and snippets.

@dongweiming
Created November 21, 2013 04:22
Show Gist options
  • Save dongweiming/7576058 to your computer and use it in GitHub Desktop.
Save dongweiming/7576058 to your computer and use it in GitHub Desktop.
发现问题
class ProcessStates:
STOPPED = 0
STARTING = 10
RUNNING = 20
BACKOFF = 30
STOPPING = 40
EXITED = 100
FATAL = 200
UNKNOWN = 1000
STOPPED_STATES = (ProcessStates.STOPPED,
ProcessStates.EXITED,
ProcessStates.FATAL,
ProcessStates.UNKNOWN)
RUNNING_STATES = (ProcessStates.RUNNING,
ProcessStates.BACKOFF,
ProcessStates.STARTING)
def getProcessStateDescription(code):
for statename in ProcessStates.__dict__:
if getattr(ProcessStates, statename) == code:
return statename
class SupervisorStates:
FATAL = 2
RUNNING = 1
RESTARTING = 0
SHUTDOWN = -1
def getSupervisorStateDescription(code):
for statename in SupervisorStates.__dict__:
if getattr(SupervisorStates, statename) == code:
return statename
class EventListenerStates:
READY = 10 # the process ready to be sent an event from supervisor
BUSY = 20 # event listener is processing an event sent to it by supervisor
ACKNOWLEDGED = 30 # the event listener processed an event
UNKNOWN = 40 # the event listener is in an unknown state
def getEventListenerStateDescription(code):
for statename in EventListenerStates.__dict__:
if getattr(EventListenerStates, statename) == code:
return statename
from functools import partial
def getState(cls, code):
for statename in cls.__dict__:
if getattr(cls, statename) == code:
return statename
class ProcessStates:
STOPPED = 0
STARTING = 10
RUNNING = 20
BACKOFF = 30
STOPPING = 40
EXITED = 100
FATAL = 200
UNKNOWN = 1000
STOPPED_STATES = (ProcessStates.STOPPED,
ProcessStates.EXITED,
ProcessStates.FATAL,
ProcessStates.UNKNOWN)
RUNNING_STATES = (ProcessStates.RUNNING,
ProcessStates.BACKOFF,
ProcessStates.STARTING)
getProcessStateDescription = partial(getState, ProcessStates)
class SupervisorStates:
FATAL = 2
RUNNING = 1
RESTARTING = 0
SHUTDOWN = -1
getSupervisorStateDescription = partial(getState, SupervisorStates)
class EventListenerStates:
READY = 10 # the process ready to be sent an event from supervisor
BUSY = 20 # event listener is processing an event sent to it by supervisor
ACKNOWLEDGED = 30 # the event listener processed an event
UNKNOWN = 40 # the event listener is in an unknown state
getEventListenerStateDescription = partial(getState, EventListenerStates)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment