~hudson-openstack/burrow/trunk

« back to all changes in this revision

Viewing changes to examples/worker_fast.py

  • Committer: Tarmac
  • Author(s): Eric Day
  • Date: 2011-08-29 16:58:05 UTC
  • mfrom: (38.1.3 examples)
  • Revision ID: tarmac-20110829165805-ksagqjhk1rbxsyqc
Added examples, bumped version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
'''Fast worker example. This does an atomic get and delete on messages
 
4
to be processed, so if the message processing fails the work is lost.'''
 
5
 
 
6
import burrow
 
7
 
 
8
 
 
9
def process_messages(queue):
 
10
    while True:
 
11
        try:
 
12
            filters = dict(detail='all', wait=10)
 
13
            messages = queue.delete_messages(filters=filters)
 
14
            for message in messages:
 
15
                # Process message here
 
16
                print message
 
17
        except burrow.NotFound:
 
18
            continue
 
19
 
 
20
 
 
21
queue = burrow.Queue('test_account', 'test_queue')
 
22
try:
 
23
    process_messages(queue)
 
24
except KeyboardInterrupt:
 
25
    pass