Skip to main content

Utilities for using Beanstalk with Flask

Project description

Utilities for using Beanstalk with Flask

Client

from flask import Flask
from flask_beanstalk import Beanstalk

app = Flask(__name__)
beanstalk = Beanstalk(app)  # or beanstalk.init_app(app)

Configuration

app.config['BEANSTALK_HOST']
app.config['BEANSTALK_PORT']
app.config['BEANSTALK_PARSE_YAML']
app.config['BEANSTALK_CONN_TIMEOUT']

Worker

import gevent
from flask_beanstalk import Worker as _Worker

class Worker(_Worker):
  def run(self, job):
    self._logger.info('Received: %r' % job.body)
    job.delete()

workers = Worker.spawn_workers(10)
try:
  while True:
    gevent.sleep(10000)
except KeyboardInterrupt:
  Worker.stop_workers(workers)

Try it out

Install and run beanstalkd if you haven’t done so yet.

git clone https://github.com/marksteve/flask-beanstalk.git
cd flask-beanstalk
mkvirtualenv flask-beanstalk
workon flask-beanstalk
python setup.py develop
python example_worker.py

On another terminal:

workon flask-beanstalk
python example.py

Go to localhost:5000 in your browser to send a job. The worker should be able to accept and process it. Try to send multiple jobs before sending a SIGINT to the worker. Jobs being worked on should be processed first before the worker shuts down.

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

Flask-Beanstalk-0.0.1.tar.gz (2.4 kB view details)

Uploaded Source

File details

Details for the file Flask-Beanstalk-0.0.1.tar.gz.

File metadata

File hashes

Hashes for Flask-Beanstalk-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3ce9639b45d5c33a93ec3daaa42d471406541037ce4f23878bb6408a655e0e82
MD5 a97484dab40e028b46f3e5fec4275f6a
BLAKE2b-256 77a843e80815037bcc3afa1a90bd92af0f7d2ebef7a672feff6a4a3b954e313a

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