messages
– Client Messaging¶
-
eventmq.client.messages.
defer_job
(socket, func, args=(), kwargs=None, class_args=(), class_kwargs=None, reply_requested=False, guarantee=False, retry_count=0, timeout=0, debounce_secs=False, 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.
Note
All passed class & fuction kwargs/args MUST be json serializable.
Parameters: - socket (socket) – eventmq socket to use for sending the message
- func (callable or str) – the callable (or string path to 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
- retry_count (int) – How many times should be retried when encountering an Exception or some other failure before giving up. (default: 0 or immediately fail)
- timeout (int) – How many seconds should we wait before killing the job default: 0 which means infinite timeout
- debounce_secs (secs) – Number of seconds to debounce the job. See debounce_deferred_job for more information.
- queue (str) – Name of queue to use when executing the job. If this value evaluates to False, the default is used. Default: is configured default queue name
Raises: TypeError
– When one or more parameters are not JSON serializable.Returns: - ID for the message/deferred job. This value will be None if there
was an error.
Return type:
-
eventmq.client.messages.
schedule
(socket, func, interval_secs=None, args=(), kwargs=None, class_args=(), class_kwargs=None, headers=('guarantee', ), queue='default', unschedule=False, cron=None)¶ Execute a task on a defined interval.
Note
All passed class & fuction kwargs/args MUST be json serializable.
Parameters: - socket (socket) – eventmq socket to use for sending the message
- func (callable) – the callable (or string path to calable) to be scheduled on a worker
- interval_secs (int) – Run job every interval_secs or None if using cron
- args (list) – list of *args to pass to the callable
- cron (string) – cron formatted string used for job schedule if interval_secs is None, i.e. ‘* * * * *‘ (every minute)
- 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.
Raises: TypeError
– When one or more parameters are not JSON serializable.Returns: - ID of the schedule message that was sent. None if there was an
error
Return type:
-
eventmq.client.messages.
send_request
(socket, message, reply_requested=False, guarantee=False, retry_count=0, timeout=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)
- timeout (int) – How many seconds should we wait before killing the job default: 0 which means infinite timeout
- queue (str) – Name of queue to use when executing the job. Default: is configured default queue name
Returns: ID of the message
Return type:
-
eventmq.client.messages.
send_schedule_request
(socket, message, interval_secs=-1, headers=(), queue=None, unschedule=False, cron='')¶ Send a SCHEDULE or UNSCHEDULE command.
Queues a message requesting that something happens on an interval for the scheduler.
Parameters: Returns: ID of the message
Return type: