~hudson-openstack/burrow/trunk

« back to all changes in this revision

Viewing changes to examples/worker.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
'''Normal worker example. This first retrieves messages to be processed
 
4
and then deletes them once work is complete.'''
 
5
 
 
6
import burrow
 
7
 
 
8
 
 
9
def process_messages(queue):
 
10
    while True:
 
11
        try:
 
12
            messages = queue.get_messages(filters=dict(wait=10))
 
13
            for message in messages:
 
14
                # Process message here
 
15
                print message
 
16
                queue.delete_message(message['id'])
 
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