Skip to main content

A simple tool for creating long-running Python workers listening for Beanstalk jobs.

Project description

A simple tool for creating long-running Python workers listening for Beanstalk jobs.

Jobs can be posted as YAML or JSON objects, with keys mapping to the callable’s keyword arguments. Passing parse=False to the __init__ method will disable YAML parsing, and the callable will be provided a single string argument containing the job’s body.

Returning True from the callable will be seen as a success and will delete the job from the queue. Returning False or None will be seen as a failure, and the job will be buried for later inspection.

If listening on multiple tubes, add the argument __tubes__ to the method to receive the tube name when the callable is executed.

Usage:

import logging
from RunnerBean import Runner

def print_message(recipient, message, __tube__):
    # accepts a job with the following structure:
    """
    message: Hello world!
    recipient: joe bloggs
    """
    print recipient, message

    print __tube__ #= 'messages'

    return True # this deletes the job from the tube

if __name__ == '__main__':
    runner = Runner(print_message,
                    parse=True, # default; job body should be parsed as YAML
                    tubes="messages", # string or list of tubes to listen on
                    host='0.0.0.0', # beanstalkd host
                    port=11300, # beanstalkd port
                    loglevel=logging.DEBUG, # set log level, default: ERROR
                    logfile='runnerbean.log' # set the logfile
                    )
    runner.run()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

RunnerBean-0.4.4.dev0.tar.gz (4.1 kB view details)

Uploaded Source

File details

Details for the file RunnerBean-0.4.4.dev0.tar.gz.

File metadata

File hashes

Hashes for RunnerBean-0.4.4.dev0.tar.gz
Algorithm Hash digest
SHA256 45c01986b947bdd978020fb0c3f0de7444ed083963944a74e3bd7932f8fb2845
MD5 39f7c82cf49579c0596170f0536fc851
BLAKE2b-256 9898cf4f2da298240385787c8b64f69b2106fff8b63d5cdd1c7415217c8579b7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page