dragonfly.implementations.at_operator module

Some template vars

Members: AtOperator Functions: Classes:

Summary

class dragonfly.implementations.at_operator.AtOperator(monitor_channel_name='slack_test', update_interval={'hours': 12}, ping_interval={'seconds': 30}, authentication_path='.project8_authentications.json', **kwargs)

Bases: dragonfly.implementations.at_operator.AtOperator

Keyword Arguments:
 
  • monitor_channel_name – the name of Slack monitor channel.
  • update_interval – the time interval between regular checks and updates.
  • authentication_path – the absolute path of the file that stores the authentication info. control_function: reference to function to be run, it must have a kwarg ‘halt_event’ which is a multiprocessing.Event. When that event, the function is expected to exit in a timely but graceful fashion. Default=None. If none, use the provided slow_mixin.slow_target method, which will just execute the worker function and terminate() it when told to do so. worker_function: reference to function which actually does the desired work.
  • name (str) – unique identifier across all dripline services (used to determine routing key)
  • calibration (str||dict) – string use to process raw get result (with .format(raw)) or a dict to use for the same purpose where raw must be a key
  • get_on_set (bool) – flag to toggle running ‘on_get’ after each ‘on_set’

monitor_channel_name: the name of Slack monitor channel. update_interval : the time interval between regular checks and updates. authentication_path : the absolute path of the file that stores the authentication info.

at_operator(channel)

Send a Slack message to @ the operator (the one listed on Google calendar, and temporary operator(s) if exists.) channel: id of the channel where the message will be sent

basic_control_target(halt_event, target, args=(), kwargs={})

A function which executes a worker function in a subprocess until either it returns, or a halt event is received. When the halt is set, the worker is terminated (the event is polled 10 times per second). There is no need to override this function as the __init__ allows another function name to be passed in (though override would work as well).

halt_event (multiprocessing.Event): event to set() in order to force termination of the subprocess target (function): the function to call in the subprocess args (tuple): items to unpack as positional args to target kwargs (dict): items to unpack as kwargs to target

check_operator_validity(new_operator_name, shift_end_time, initial, regular_check)

Check whether nor not the given new operator name is valid. If so, update information for current operator. new_operator_name: the full name of the new operator shift_end_time : the end time corresponding to this operator initial : True when called the first time, False otherwise regular_check : True when called during a regular check, False otherwise

command_hello(channel, user_id)

Display a greeting message in a Slack channel. channel: id of the channel where the message will be sent user_id: id of the user who called the command

command_help(channel)

Display a helper message in a Slack channel. channel: id of the channel where the message will be sent

command_removetempoperator(channel, user_id, operator_name='')

Remove the given temporary operator. channel : id of the Slack channel where the message will be sent user_id : id of the user who called the command operator_name: the temporary operator to be removed; the user itself will be removedd if empty

command_tempoperator(channel, user_id, operator_name='')

Add a new temporary operator. channel : id of the Slack channel where the message will be sent user_id : id of the user who called the command operator_name: new temporary operator to be added; the user itself will be added if empty

command_whoisop(channel)

Display current and temporary operator(s) to a Slack channel. channel: id of the channel where the message will be sent

construct_channel_dictionaries()

Return 2 dictionaries storing information of Slack channels: channel name to id, and channel id to name.

construct_command_dictionary()

Return a dictionary containing all Slack helper commands.

construct_user_dictionaries()

Return 3 dictionaries storing information of Slack users: full name to id, id to username, and username to id.

control_process_is_running()

wrapper to call multiprocessing.Process.is_alive()

get_calendar_credentials()

Return google calendar credentials.

get_event_list(creds)

Return a list of events found from the given calendar. creds: google calendar credentials.

get_event_time(event, start)

Return the start/end time of a given event, without the timezone info. event: a single event retrieved from google calendar start: True if looking for start time, False if looking for end time

get_operator_name_and_time(events)

Return the name of current operator, the time when his/her shift ends, and the time when the next shift begins. events: a list of events found from google calendar

get_slack_client()

Set up the slack client.

handle_request(channel, method, properties, request)
initialize()

Try to check and assign values to instance variables before entering the main loop. Return a list of Google Calendar events if everything seems to be in order.

is_locked
join_control_process(timeout=None)

wrapper to call multiprocessing.Process.join(timeout=None)

lock(lockout_key=None, *args, **kwargs)
lockout_key
on_cmd(*args, **kwargs)

WARNING! if you override this method, you must ensure you deal with lockout properly

on_config(attribute, value=None)

configure a property again

WARNING! if you override this method, you must ensure you deal with lockout properly

parse_output(rtm_output, bot_id)

Parse the given Slack output and check whether or not I am called. rtm_output: Slack runtime output bot_id : my bot id

ping(*args, **kwargs)

ignore all details and respond with an empty message

run()

The main loop.

send_message(channel, text)

Send a given message to a given Slack channel if the channel exists. channel: Slack channel id text : a string to be sent

set_condition(*args, **kwargs)

To actually do something inside a class, the set_condition should be implemented in the class itself.

start_control_process()

wrapper to call multiprocessing.Process.start()

stop_control_process(timeout=0)

Signal the subprocess that it should terminate by setting the halt_event and then terminate it.

timeout (int) [seconds]: number of seconds to allow the process to attempt to exit gracefully, after which terminate() is called if needed.
Note that 0 seconds is valid and results in terminate being called immediately after the halt is set. Note that None is also valid and indicates that the process will be given unlimited time to exit cleanly. This method will join() the process and therefore blocks until the subprocess returns… Do this only with utmost caution
unlock(*args, **kwargs)

End of modules condition

Data:

End of data condition