Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added timeout functionality to get, released 0.5

  • Loading branch information...
commit 88379f9799271067c87ddbd2ecaa7bab1f748a83 1 parent c5b7c75
Paddy Foran authored
Showing with 30 additions and 6 deletions.
  1. +2 −2 README.md
  2. +12 −3 iron_mq.py
  3. +1 −1  setup.py
  4. +15 −0 test.py
4 README.md
View
@@ -78,9 +78,9 @@ queue.post(*[str(i) for i in range(10)])
### **Pop** a message off the queue:
```python
-queue.get(max=10) # {"messages": [{'id': '..', 'body': '..'}, ..]}
+queue.get(max=10, timeout=None) # {"messages": [{'id': '..', 'body': '..'}, ..]}
```
-Set max to the number of messages to return, 1 by default.
+Set max to the number of messages to return, 1 by default. An optional `timeout` parameter can be used to specify a per-message timeout, or the timeout the message was posted with will be used.
When you pop/get a message from the queue, it will NOT be deleted.
It will eventually go back onto the queue after a timeout if you don't delete it (default timeout is 60 seconds).
15 iron_mq.py
View
@@ -77,15 +77,24 @@ def post(self, *messages):
return result['body']
- def get(self, max=None):
+ def get(self, max=None, timeout=None):
"""Executes an HTTP request to get a message off of a queue.
Keyword arguments:
max -- The maximum number of messages to pull. Defaults to 1.
"""
url = "queues/%s/messages" % self.name
+ qitems = {}
if max is not None:
- url = "%s?n=%s" % (url, max)
+ qitems["n"] = max
+ if timeout is not None:
+ qitems["timeout"] = timeout
+ qs = []
+ for k, v in qitems.items():
+ qs.append("%s=%s" % (k, v))
+ qs = "&".join(qs)
+ if qs != "":
+ url = "%s?%s" % (url, qs)
result = self.client.get(url)
@@ -181,7 +190,7 @@ def _prepare_subscribers(self, *subscribers):
class IronMQ:
NAME = "iron_mq_python"
- VERSION = "0.4"
+ VERSION = "0.5"
client = None
name = None
2  setup.py
View
@@ -4,7 +4,7 @@
name = "iron-mq",
py_modules = ["iron_mq"],
install_requires = ["iron_core"],
- version = "0.4",
+ version = "0.5",
description = "Client library for IronMQ, a message queue in the cloud",
author = "Iron.io",
author_email = "thirdparty@iron.io",
15 test.py
View
@@ -22,6 +22,21 @@ def test_getMessage(self):
message = "%s" % message["messages"][0]["body"]
self.assertEqual(msg, message)
+ def test_getMessageTimeout(self):
+ msg = "%s" % time.time()
+ q = self.mq.queue("test_queue")
+ q.clear()
+ q.post(msg)
+ message = q.get(timeout=180)
+ message = "%s" % message["messages"][0]["body"]
+ self.assertEqual(msg, message)
+ time.sleep(120)
+ m2 = q.get()
+ self.assertEqual(0, len(m2["messages"]))
+ time.sleep(120)
+ m3 = q.get()
+ self.assertEqual(msg, message)
+
def test_deleteMessage(self):
q = self.mq.queue("test_queue")
size = q.size()
Please sign in to comment.
Something went wrong with that request. Please try again.