Skip to content

Instantly share code, notes, and snippets.

@mikeengland
Created July 15, 2018 14:32
Show Gist options
  • Save mikeengland/af020bfddfc60d97768e2a990ed888a3 to your computer and use it in GitHub Desktop.
Save mikeengland/af020bfddfc60d97768e2a990ed888a3 to your computer and use it in GitHub Desktop.
Beanstalkd basic consumer/producer example using pystalkd
from pystalkd.Beanstalkd import Connection
conn = Connection(host='127.0.0.1', port=11300)
# watch the queue1 tube
conn.watch('queue1')
# stop watching the default tube
conn.ignore('default')
while True:
# block until a job is sent on the queue
job = conn.reserve()
# This is run when a job is found - perform processing here
print(job.job_id, job.body)
# Remove the job from beanstalkd once processing is completed
job.delete()
from pystalkd.Beanstalkd import Connection
conn = Connection(host='127.0.0.1', port=11300)
# The queue to sent a message on
conn.use('queue1')
# job times out and is put back on queue after 4 hours
# A priority can be between 0 and 4,294,967,295 - 0 is the most urgent
conn.put('hello world', priority=0, ttr=14400)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment