manager Module

The manager module is a core component of gaffer. A Manager is responsible of maintaining processes and allows you to interract with them.

Classes

class gaffer.manager.Manager(loop=None)[source]

Bases: object

Manager - maintain process alive

A manager is responsible of maintaining process alive and manage actions on them:

  • increase/decrease the number of processes / process template
  • start/stop processes
  • add/remove process templates to manage

The design is pretty simple. The manager is running on the default event loop and listening on events. Events are sent when a process exit or from any method call. The control of a manager can be extended by adding apps on startup. For example gaffer provides an application allowing you to control processes via HTTP.

Running an application is done like this:

# initialize the application with the default loop
loop = pyuv.Loop.default_loop()
m = Manager(loop=loop)

# start the application
m.start(apps=[HttpHandler])

.... # do smth

m.stop() # stop the controlller
m.run() # run the event loop

Note

The loop can be omitted if the first thing you do is launching a manager. The run function is here for convenience. You can of course just run loop.run() instead

Warning

The manager should be stopped the last one to prevent any lock in your application.

active
commit(name, graceful_timeout=0, env=None)[source]

Like ``scale(1) but the process won’t be kept alived at the end. It is also not handled uring scaling or reaping.

get(name)[source]

get a job config

get_process(pid)[source]

get an OS process by ID. A process is a gaffer.Process instance attached to a process state that you can use.

get_process_id()[source]

generate a process id

info(name)[source]

get job’ infos

jobs(sessionid=None)[source]
jobs_walk(callback, sessionid=None)[source]
kill(pid, sig)[source]

send a signal to a process

killall(name, sig)[source]

send a signal to all processes of a job

list(name=None)[source]
load(config, sessionid=None, env=None, start=True)[source]

load a process config object.

Args:

  • config: a process.ProcessConfig instance
  • sessionid: Some processes only make sense in certain contexts. this flag instructs gaffer to maintain this process in the sessionid context. A context can be for example an application. If no session is specified the config will be attached to the default session.
  • env: dict, None by default, if specified the config env variable will be updated with the env values.
manage(name)[source]
monitor(listener, name)[source]

get stats changes on a process template or id

pids(name=None)[source]
reload(name, sessionid=None)[source]

reload a process config. The number of processes is resetted to the one in settings and all current processes are killed

restart(callback=None)[source]

restart all processes in the manager. This function is threadsafe

run()[source]

Convenience function to use in place of loop.run() If the manager is not started it raises a RuntimeError.

Note: if you want to use separately the default loop for this thread then just use the start function and run the loop somewhere else.

scale(name, n)[source]

Scale the number of processes in for a job. By using this function you can increase, decrease or set the number of processes in a template. Change is handled once the event loop is idling

n can be a positive or negative integer. It can also be a string containing the opetation to do. For example:

m.scale("sometemplate", 1) # increase of 1
m.scale("sometemplate", -1) # decrease of 1
m.scale("sometemplate", "+1") # increase of 1
m.scale("sometemplate", "-1") # decrease of 1
m.scale("sometemplate", "=1") # set the number of processess to 1
send(pid, lines, stream=None)[source]

send some data to the process

sessions
start(apps=[])[source]

start the manager.

start_job(name)[source]

Start a job from which the config have been previously loaded

stats(name)[source]

return job stats

stop(callback=None)[source]

stop the manager. This function is threadsafe

stop_job(name)[source]

stop a jon. All processes of this job are stopped and won’t be restarted by the manager

stop_process(pid)[source]

stop a process

stopall(name)[source]

stop all processes of a job. Processes are just exiting and will be restarted by the manager.

subscribe(topic)[source]
unload(name_or_process, sessionid=None)[source]

unload a process config.

unmonitor(listener, name)[source]

get stats changes on a process template or id

unsubscribe(topic, channel)[source]
update(config, sessionid=None, env=None, start=False)[source]

update a process config. All processes are killed

wakeup()[source]
walk(callback, name=None)[source]