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_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.
-
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.
- config: a
-
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
-
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
-
sessions
¶
-
stop_job
(name)[source]¶ stop a jon. All processes of this job are stopped and won’t be restarted by the manager
-
stopall
(name)[source]¶ stop all processes of a job. Processes are just exiting and will be restarted by the manager.