jobs
– Client Job Helpers¶
-
class
eventmq.client.jobs.
Job
(broker_addr=None, queue=None, async=True, *args, **kwargs)¶ Defines a deferred EventMQ job.
Note
All passed class & function kwargs/args MUST be json serializable.
Usage:
from eventmq import job @job(queue='messaging') def send_email(recipient, subject, message): from email.mime.text import MIMEText import smtplib msg = MIMEText(message) msg['Subject'] = subject msg['From'] = 'no-reply@foobar.io' msg['To'] = recipient s = smtplib.SMTP('smtp.gmail.com') s.login('me@gmail.com', 'my-app-password') s.sendmail('me@gmail.com', [recipient,], msg.as_string()) s.quit()
-
__init__
(broker_addr=None, queue=None, async=True, *args, **kwargs)¶ Parameters: - queue (str) – Name of the queue this function should be executed
in. If no queue provided
default
is used. - broker_addr (str) – Address of the broker to send the job to. If no
address is given then the value of the environment variable
EMQ_BROKER_ADDR
will be used, If that is undefined a warning will be emitted and the job will be run synchronously. - async (bool) – If you want to run all executions of a particular job synchronously but still decorate it with the job decorator you can set this to False. This is useful for unit tests.
- queue (str) – Name of the queue this function should be executed
in. If no queue provided
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
eventmq.client.jobs.
job
(func, broker_addr=None, queue=None, async=True, *args, **kwargs)¶ Functional decorator helper for creating a deferred eventmq job. See
Job
for more information.
-
eventmq.client.jobs.
schedule
(func, broker_addr=None, interval_secs=None, args=(), kwargs=None, class_args=(), class_kwargs=None, headers=('guarantee', ), queue='default', cron=None)¶ Execute a task on a defined interval.
Note
All passed class & function kwargs/args MUST be json serializable.
Parameters: - func (callable) – the callable (or string path to calable) to be scheduled on a worker
- broker_addr (str) – Address of the broker to send the job to. If no
address is given then the value of the environment variable
EMQ_BROKER_ADDR
will be used. - interval_secs (int) – Run job every interval_secs or None if using cron
- 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.
- cron (string) – cron formatted string used for job schedule if interval_secs is None, i.e. ‘* * * * *‘ (every minute)
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.jobs.
unschedule
(func, broker_addr=None, interval_secs=None, args=(), kwargs=None, class_args=(), class_kwargs=None, headers=('guarantee', ), queue='default', cron=None)¶ Stop periodically executing a task
Note
All passed class & function kwargs/args MUST be json serializable.
Parameters: - func (callable) – the callable (or string path to calable) to be scheduled on a worker
- broker_addr (str) – Address of the broker to send the job to. If no
address is given then the value of the environment variable
EMQ_BROKER_ADDR
will be used. - interval_secs (int) – Run job every interval_secs or None if using cron
- 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.
- cron (string) – cron formatted string used for job schedule if interval_secs is None, i.e. ‘* * * * *‘ (every minute)
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: