pyfarm.agent.service module

Manager Service

Sends and receives information from the master and performs systems level tasks such as log reading, system information gathering, and management of processes.

class pyfarm.agent.service.Agent[source]

Bases: object

Main class associated with getting getting the internals of the agent’s operations up and running including adding or updating itself with the master, starting the periodic task manager, and handling shutdown conditions.

classmethod agent_api()[source]

Return the API url for this agent or None if agent-id has not been set

classmethod agents_endpoint()[source]

Returns the API endpoint for used for updating or creating agents on the master

should_reannounce()[source]

Small method which acts as a trigger for reannounce()

reannounce()[source]

Method which is used to periodically contact the master. This method is generally called as part of a scheduled task.

system_data(requery_timeoffset=False)[source]

Returns a dictionary of data containing information about the agent. This is the information that is also passed along to the master.

build_http_resource()[source]
start(shutdown_events=True, http_server=True)[source]

Internal code which starts the agent, registers it with the master, and performs the other steps necessary to get things running.

Parameters:
  • shutdown_events (bool) – If True register all shutdown events so certain actions, such as information the master we’re going offline, can take place.
  • http_server (bool) – If True then construct and serve the externally facing http server.
stop()[source]

Internal code which stops the agent. This will terminate any running processes, inform the master of the terminated tasks, update the state of the agent on the master.

sigint_handler(*_)[source]
post_shutdown_to_master(stop_reactor=True)[source]

This method is called before the reactor shuts down and lets the master know that the agent’s state is now offline

errback_post_agent_to_master(failure)[source]

Called when there’s a failure trying to post the agent to the master. This is often because of some lower level issue but it may be recoverable to we retry the request.

callback_post_agent_to_master(response)[source]

Called when we get a response after POSTing the agent to the master.

post_agent_to_master()[source]

Runs the POST request to contact the master. Running this method multiple times should be considered safe but is generally something that should be avoided.

callback_post_free_ram(response)[source]

Called when we get a response back from the master after POSTing a change for free_ram

errback_post_free_ram(failure)[source]

Error handler which is called if we fail to post a ram update to the master for some reason

post_free_ram()[source]

Posts the current nu

callback_free_ram_changed(change_type, key, new_value, old_value)[source]

Callback used to decide and act on changes to the config['ram'] value.

errback_post_cpu_count_change(failure)[source]

Error handler which is called if we fail to post a cpu count update to an existing agent for some reason.

callback_post_cpu_count_change(response)[source]

Called when we received a response from the master after

post_cpu_count(run=True)[source]

POSTs CPU count changes to the master

callback_cpu_count_changed(change_type, key, new_value, old_value)[source]

Callback used to decide and act on changes to the config['cpus'] value.

callback_agent_id_set(change_type, key, new_value, old_value, shutdown_events=True)[source]

When agent-id is created we need to:

  • Register a shutdown event so that when the agent is told to shutdown it will notify the master of a state change.
  • Star the scheduled task manager
pyfarm.agent.service.random() → x in the interval [0, 1).