-
Notifications
You must be signed in to change notification settings - Fork 4
Callback functions
Detcord implements several callback functions so that you may have tasks executed at certain times. An example use case (and the reason why its implemented) is for logging. You may log whenever detcord does anything.
The four callbacks implemented by detcord are:
- on_detcord_begin(*args, **kwargs)
- on_detcord_action(*args, **kwargs)
- on_detcord_action_fail(*args, **kwargs)
- on_detcord_end(*args, **kwargs)
You may implement any of the callbacks by defining the functions in your detfile.
Note: The
begin
andend
callbacks are called frombin/detonate
. Theaction
andaction_fail
are called from the@action
decorator. The decorator calls__main__.on_detcord_action()
. If you are loading detcord through your own python code, try to make sure that you callbegin
andend
and importaction
andaction_fail
from the detfile.
This callback is called right before the first @action
is run. This function is called in detonate
right before it starts executing actions.
def on_detcord_begin(detfile="", hosts=[], actions=[], threading=False):
-
detfile
(str): The file location of the detfile that is being called -
hosts
(list): An array of the hosts that the actions are being run against -
actions
(list): An array of the actions that are being run -
threading
(bool): Whether or not the actions are being threaded
This callback is called whenever an @action
is completed.
return_value
will always beNone
unlesssilent
is specified in the environment.
def on_detcord_action(host="", action="", return_value=None):
-
host
(str): The name of the host that the action was run against -
action
(str): The name of the action that was being run -
return_value
(obj): The return value of the function.None
This callback is called whenever an @action
fails.
def on_detcord_action_fail(host="", action="", exception=None):
-
host
(str): The name of the host that the action was run against -
action
(str): The name of the action that was being run -
exception
(Exception): The exception that was raised by the action
This callback is called whenever a detfile is finished running.
def on_detcord_end(detfile=""):
-
detfile
(str): The file location of the detfile that was called