Created
August 20, 2012 05:35
-
-
Save utsavsabharwal/3401344 to your computer and use it in GitHub Desktop.
Get SQS Count
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import gzip | |
| import base64 | |
| import simplejson | |
| from cStringIO import StringIO | |
| import boto.exception | |
| import boto.s3 | |
| import boto.s3.connection | |
| import boto.s3.key | |
| import traceback | |
| import boto.sqs | |
| import boto.sqs.connection | |
| import smtplib | |
| import time | |
| class _QueueItemMessage(boto.sqs.message.RawMessage): | |
| def set_body(self, docid, url=None): | |
| if url is None: | |
| if docid != '': | |
| assert isinstance(docid, dict), 'Unexpected docid: %r' % docid | |
| self._body = docid | |
| else: | |
| self._body = dict(docid=docid, url=url) | |
| def encode(self, value): | |
| return base64.standard_b64encode(simplejson.dumps(value)) | |
| def decode(self, value): | |
| return simplejson.loads(base64.b64decode(value)) | |
| class SQS(object): | |
| def __init__(self, name): | |
| self.name = name | |
| self.setup_sqs_queue() | |
| def setup_sqs_queue(self): | |
| sqsconn = boto.sqs.connection.SQSConnection() | |
| self.queue = sqsconn.get_queue(self.name) | |
| while True: | |
| count = self.queue.count() | |
| print count | |
| time.sleep(60) | |
| print count, (count - self.queue.count()) | |
| #ss = SQS(name="docprocessor_queue_beta_spider") | |
| ss = SQS(name="docprocessor_queue_beta_intl_spider") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment