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 untilrepeat_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 takesfunction
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 callingfunction
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 handlerepeat_max
properly.
- delay (int) –
-
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.
-
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:
-
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.
-
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.
-
classmethod