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

shutting_down
repeating_call(delay, function, function_args=None, function_kwargs=None, now=True, repeat_max=None, function_id=None)[source]

Causes function to be called repeatedly up until repeat_max or until stopped.

Parameters:
  • delay (int) –

    Number of seconds to delay between calls of function.

    Note

    delay is an approximate interval between when one call ends and the next one begins. The exact time can vary due to how the Twisted reactor runs, how long it takes function to run and what else may be going on in the agent at the time.

  • function – A callable function to run
  • function_args (tuple, list) – Arguments to pass into function
  • function_kwargs (dict) – Keywords to pass into function
  • now (bool) – If True then run function right now in addition to scheduling it.
  • repeat_max (int) – Repeat calling function this may times. If not provided then we’ll continue to repeat calling function until the agent shuts down.
  • function_id (uuid.UUID) – Used internally to track a function’s execution count. This keyword exists so if you call repeating_call() multiple times on the same function or method it will handle repeat_max properly.
should_reannounce()[source]

Small method which acts as a trigger for reannounce()

reannounce(*args, **kwargs)[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(*args, **kwargs)[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(*args, **kwargs)[source]

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

post_agent_to_master(*args, **kwargs)[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_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
callback_shutting_down_changed(change_type, key, new_value, old_value)[source]

When shutting_down is changed in the configuration, set or reset self.shutdown_timeout