messages – Client Messaging

eventmq.client.messages.build_module_path(func)

Builds the module path in string format for a callable.

Parameters:func (callable) – The function or method to build the path for
Returns:(import path (w/ class seperated by a ‘:’), callable name) or (None, None) on error
Return type:list
eventmq.client.messages.defer_job(socket, func, args=(), kwargs=None, class_args=(), class_kwargs=None, reply_requested=False, guarantee=False, retry_count=0, queue='default')

Used to send a job to a worker to execute via socket.

This tries not to raise any exceptions so use some of the message flags to guarentee things.

Parameters:
  • socket (socket) – eventmq socket to use for sending the message
  • func (callable) – the callable to be deferred to a worker
  • args (list) – list of *args for the callable
  • kwargs (dict) – dict of **kwargs for the callable
  • class_args (list) – list of *args to pass to the the class when initializing (if applicable).
  • class_kwargs (dict) – dict of **kwargs to pass to the class when initializing (if applicable).
  • reply_requested (bool) – request the return value of func as a reply
  • guarantee (bool) – (Give your best effort) to guarantee that func is executed. Exceptions and things will be logged.
  • retry_count (int) – How many times should be retried when encountering an Exception or some other failure before giving up. (default: 0 or immediatly fail)
  • queue (str) – Name of queue to use when executing the job. Default: is configured default queue name
Returns:

True if the message was successfully queued, False if something went wrong. If something did go wrong check the logs for details.

Return type:

bool

eventmq.client.messages.job(block=False)

run the decorated function on a worker

Parameters:block (bool) – Set to True if you wish to block and wait for the response. This may be useful for running quick but cpu intesive that would otherwise overwhelm a box that has to do it all alone. (decryption?)
eventmq.client.messages.schedule(socket, func, interval_secs, args=(), kwargs=None, class_args=(), class_kwargs=None, headers=('guarantee', ), queue='default', unschedule=False)

Execute a task on a defined interval.

Parameters:
  • socket (socket) – eventmq socket to use for sending the message
  • func (callable) – the callable to be scheduled on a worker
  • minutes (int) – minutes to wait in between executions
  • args (list) – list of *args to pass to the callable
  • kwargs (dict) – dict of **kwargs to pass to the callable
  • class_args (list) – list of *args to pass to the class (if applicable)
  • class_kwargs (dict) – dict of **kwargs to pass to the class (if applicable)
  • headers (list) – list of strings denoting enabled headers. Default: guarantee is enabled to ensure the scheduler schedules the job.
  • queue (str) – name of the queue to use when executing the job. The default value is the default queue.
eventmq.client.messages.send_request(socket, message, reply_requested=False, guarantee=False, retry_count=0, queue=None)

Send a REQUEST command.

Default headers are always all disabled by default. If they are included in the headers then they have been enabled.

To execute a task, the message should be formatted as follows: {subcommand(str), {

# dot path location where callable can be imported. If callable is a # method on a class, the class should always come last, and be # seperated with a colon. (So we know to instantiate on the receiving # end) ‘path’: path(str), # function or method name to run ‘callable’: callable(str), # Optional args for callable ‘args’: (arg, arg), # Optional kwargs for callable ‘kwargs’: {‘kwarg’: kwarg}, # Optional class args, kwargs ‘class_args’: (arg2, arg3), ‘class_kwargs’: {‘kwarg2’: kwarg}

}

} :param socket: Socket to use when sending message :type socket: socket :param message: message to send to socket :param reply_requested: request the return value of func as a reply :type reply_requested: bool :param guarantee: (Give your best effort) to guarantee that func is

executed. Exceptions and things will be logged.
Parameters:
  • retry_count (int) – How many times should be retried when encountering an Exception or some other failure before giving up. (default: 0 or immediatly fail)
  • queue (str) – Name of queue to use when executing the job. Default: is configured default queue name
eventmq.client.messages.send_schedule_request(socket, interval_secs, message, headers=(), queue=None, unschedule=False)

Send a SCHEDULE or UNSCHEDULE command.

Queues a message requesting that something happens on an interval for the scheduler.

Parameters:
  • socket (socket) –
  • interval_secs (int) –
  • message – Message to send socket.
  • headers (list) – List of headers for the message
  • queue (str) – name of queue the job should be executed in