From 5eabb8fefbcc2ec64904fe5c805653f7abe2f853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D0=B4=D0=B8=D0=BC=20=D0=9B=D0=B8=D0=B2=D0=B5?= =?UTF-8?q?=D0=BD=D1=86=D0=B5=D0=B2?= Date: Tue, 12 Feb 2013 20:06:03 +0400 Subject: [PATCH 1/7] A version of readme with my comments + changes --- README.md | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7f0d19d..34a66a4 100644 --- a/README.md +++ b/README.md @@ -57,8 +57,10 @@ queue = ironmq.queue("test_queue") ```python queue.post("Hello world") ``` +// Maybe a little more verbose here? -Message can be described by dict: +This message will have the default properties. +In order to customize them, Message can be described by dict: ```python message = { @@ -70,18 +72,43 @@ message = { queue.post(message) ``` +// +// For each of the above comments it would be nice to clarify when the countdown begins. +// For instance, for "expires_in" it's unclear whether this countdown restarts when a message is popped and then pushed back on the queue +// I suggest the following: + + +```python +message = { + "body" : "Test Message", + "timeout" : 120, # Timeout, in seconds. After timeout, item will be placed back on queue. Defaults to 60. + "delay" : 5, # The item will not be available on the queue until this many seconds have passed since message being pushed. Defaults to 0. + "expires_in" : 2*24*3600 # How long, in seconds, to keep the item on the queue before it is deleted. When a message is popped and then pushed back on the queue the countdown restarts. +} +queue.post(message) +``` + We can post several messages at once: ```python queue.post("more", "and more", "and more") queue.post(*[str(i) for i in range(10)]) ``` +// +// All the example messages are strings: a user might think that only strings can be passed to "push" and "post" functions. +// If it's not so, adding an example with int/float would help avoid misunderstanding +// + ### **Pop** a message off the queue: ```python queue.get() ``` 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). + +// Stating constants several times throughout the manual is unsafe because if it gets altered +// an editor will have to change one statement and forget about the other one. + ### **Delete** a message from the queue: ```python queue.delete(message_id) @@ -104,9 +131,11 @@ queue.info() queue.size() # 15 queue.name queue.total_messages() # 17 -queue.id() # u'502d03d3211a8f5e7742d224' +queue.id() # u'502d03d3211a8f5e7742d224' ``` +// How can total_messages be greater than size? + # Full Documentation You can find more documentation here: From b12e2b66a6c996a3899a4867ad60b8f98c2901e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D0=B4=D0=B8=D0=BC=20=D0=9B=D0=B8=D0=B2=D0=B5?= =?UTF-8?q?=D0=BD=D1=86=D0=B5=D0=B2?= Date: Tue, 12 Feb 2013 23:59:28 +0400 Subject: [PATCH 2/7] Implemented a verbose version of Get --- README.md | 9 +++++++++ iron_mq.py | 8 ++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 34a66a4..9189a47 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,15 @@ queue.post(*[str(i) for i in range(10)]) ```python queue.get() ``` +This will pop a message off the queue and return its body (aka a string) +In order to find out its attributes, use the following syntax: + +```python +message = queue.get(verbose=True) +``` + +Now you have access to all the data associated with this message, i.e. message["timeout"] + 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). diff --git a/iron_mq.py b/iron_mq.py index 34e51a7..db0e612 100644 --- a/iron_mq.py +++ b/iron_mq.py @@ -87,10 +87,11 @@ def post(self, *messages): return result['body'] - def get(self, max=None): + def get(self, verbose=False, max=None): """Executes an HTTP request to get a message off of a queue. Keyword arguments: + verbose -- If true, the entire dict is returned instead of the message body. max -- The maximum number of messages to pull. Defaults to 1. """ @@ -99,7 +100,10 @@ def get(self, max=None): n = "&n=%s" % max url = "queues/%s/messages?%s" % (self.name, n) result = self.client.get(url) - return result['body'] + if verbose is True: + return result + else: + return result['body'] class IronMQ: From aa7399a47fd6055af6a7cd250ef9377c6efd4c7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D0=B4=D0=B8=D0=BC=20=D0=9B=D0=B8=D0=B2=D0=B5?= =?UTF-8?q?=D0=BD=D1=86=D0=B5=D0=B2?= Date: Sat, 16 Feb 2013 02:16:50 +0400 Subject: [PATCH 3/7] Added an option: when this option is active and the message queue is empty "get" function waits for a message to be pushed into the queue --- README.md | 8 ++++++++ iron_mq.py | 32 ++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 9189a47..286008a 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,14 @@ It will eventually go back onto the queue after a timeout if you don't delete it // Stating constants several times throughout the manual is unsafe because if it gets altered // an editor will have to change one statement and forget about the other one. +Note that all of the above will return None if the queue is empty. +```python +message = queue.get(verbose=False, period=0.5) +``` +will activate persistance so that a function will not be completed until it actually recieves a message. +An attempt to pop a message will be done every "period" seconds (2 times a second in the example) + + ### **Delete** a message from the queue: ```python queue.delete(message_id) diff --git a/iron_mq.py b/iron_mq.py index db0e612..1936a8d 100644 --- a/iron_mq.py +++ b/iron_mq.py @@ -1,5 +1,6 @@ import iron_core import urllib +import time try: import json except: @@ -87,23 +88,30 @@ def post(self, *messages): return result['body'] - def get(self, verbose=False, max=None): + def get(self, verbose=False, period=0, max=None): """Executes an HTTP request to get a message off of a queue. Keyword arguments: - verbose -- If true, the entire dict is returned instead of the message body. + wait -- If true and the queue is empty, the function waits until a message appears + verbose -- If true, the entire dict is returned instead of the message body. max -- The maximum number of messages to pull. Defaults to 1. """ - - n = "" - if max is not None: - n = "&n=%s" % max - url = "queues/%s/messages?%s" % (self.name, n) - result = self.client.get(url) - if verbose is True: - return result - else: - return result['body'] + result = None + while (result == None): + n = "" + if max is not None: + n = "&n=%s" % max + url = "queues/%s/messages?%s" % (self.name, n) + result = self.client.get(url) + + if period == 0: + break + sleep(period) + + if verbose is True: + return result + else: + return result['body'] class IronMQ: From 490d9eedf8a3ca0ec0e1248443739fa244b566f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D0=B4=D0=B8=D0=BC=20=D0=9B=D0=B8=D0=B2=D0=B5?= =?UTF-8?q?=D0=BD=D1=86=D0=B5=D0=B2?= Date: Mon, 25 Feb 2013 20:29:16 +0400 Subject: [PATCH 4/7] Revert "Added an option: when this option is active and the message queue is empty "get" function waits for a message to be pushed into the queue" This reverts commit aa7399a47fd6055af6a7cd250ef9377c6efd4c7a. Reverted the previous commit as unnecessary. --- README.md | 8 -------- iron_mq.py | 32 ++++++++++++-------------------- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 286008a..9189a47 100644 --- a/README.md +++ b/README.md @@ -118,14 +118,6 @@ It will eventually go back onto the queue after a timeout if you don't delete it // Stating constants several times throughout the manual is unsafe because if it gets altered // an editor will have to change one statement and forget about the other one. -Note that all of the above will return None if the queue is empty. -```python -message = queue.get(verbose=False, period=0.5) -``` -will activate persistance so that a function will not be completed until it actually recieves a message. -An attempt to pop a message will be done every "period" seconds (2 times a second in the example) - - ### **Delete** a message from the queue: ```python queue.delete(message_id) diff --git a/iron_mq.py b/iron_mq.py index 1936a8d..db0e612 100644 --- a/iron_mq.py +++ b/iron_mq.py @@ -1,6 +1,5 @@ import iron_core import urllib -import time try: import json except: @@ -88,30 +87,23 @@ def post(self, *messages): return result['body'] - def get(self, verbose=False, period=0, max=None): + def get(self, verbose=False, max=None): """Executes an HTTP request to get a message off of a queue. Keyword arguments: - wait -- If true and the queue is empty, the function waits until a message appears - verbose -- If true, the entire dict is returned instead of the message body. + verbose -- If true, the entire dict is returned instead of the message body. max -- The maximum number of messages to pull. Defaults to 1. """ - result = None - while (result == None): - n = "" - if max is not None: - n = "&n=%s" % max - url = "queues/%s/messages?%s" % (self.name, n) - result = self.client.get(url) - - if period == 0: - break - sleep(period) - - if verbose is True: - return result - else: - return result['body'] + + n = "" + if max is not None: + n = "&n=%s" % max + url = "queues/%s/messages?%s" % (self.name, n) + result = self.client.get(url) + if verbose is True: + return result + else: + return result['body'] class IronMQ: From 532ad89c3bc78bd430b76f6b7d1a4591431c490f Mon Sep 17 00:00:00 2001 From: iHuman0x60 Date: Mon, 25 Feb 2013 21:43:47 +0400 Subject: [PATCH 5/7] Touch/Peek/Release documentation --- README.md | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9189a47..7752133 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,28 @@ queue.delete(message_id) ``` Delete a message from the queue when you're done with it. -### ***Clear*** a queue: +### **Touch** a message: +```python +queue.touch(message_id) +``` +Touching a popped message extends its timeout by the duration specified when the message was created, which is 60 seconds by default. +After the timeout it will be placed back onto the queue. + +### **Release** a message: +```python +queue.release(message_id) +``` +Release is opposite to Touch. +Releasing a reserved message unreserves the message and puts it back on the queue as if the message had timed out. + +### **Peek** at a message: +```python +queue.peek() +``` +Use this instead of Get if you wish the message to remain on the queue. + + +### **Clear** a queue: ```python queue.clear() ``` @@ -143,8 +164,6 @@ queue.total_messages() # 17 queue.id() # u'502d03d3211a8f5e7742d224' ``` -// How can total_messages be greater than size? - # Full Documentation You can find more documentation here: From 8335d8d5adb8287d05553ad21e8100dce09229cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D0=B4=D0=B8=D0=BC=20=D0=9B=D0=B8=D0=B2=D0=B5?= =?UTF-8?q?=D0=BD=D1=86=D0=B5=D0=B2?= Date: Wed, 27 Feb 2013 13:18:26 +0400 Subject: [PATCH 6/7] Touch/Peek/Release implementation --- .gitignore | 1 + iron_mq.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index d11a899..3b94fda 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ config.ini dist build eggs +.idea diff --git a/iron_mq.py b/iron_mq.py index db0e612..fd85ff6 100644 --- a/iron_mq.py +++ b/iron_mq.py @@ -91,7 +91,7 @@ def get(self, verbose=False, max=None): """Executes an HTTP request to get a message off of a queue. Keyword arguments: - verbose -- If true, the entire dict is returned instead of the message body. + verbose -- If true, the entire dict is returned instead of the message body. max -- The maximum number of messages to pull. Defaults to 1. """ @@ -100,10 +100,53 @@ def get(self, verbose=False, max=None): n = "&n=%s" % max url = "queues/%s/messages?%s" % (self.name, n) result = self.client.get(url) - if verbose is True: + if verbose is True: return result - else: - return result['body'] + else: + return result['body'] + + + def peek(self, verbose=False, max=None): + """Executes an HTTP request to peek at a message (get a message so that it remains on the queue). + + Arguments: + verbose -- If true, the entire dict is returned instead of the message body. + max -- The maximum number of messages to pull. Defaults to 1. + """ + + n = "" + if max is not None: + n = "&n=%s" % max + url = "queues/%s/messages/peek?%s" % (self.name, n) + result = self.client.get(url) + if verbose is True: + return result + else: + return result['body'] + + + def touch(self, message_id): + """Executes an HTTP request to touch a message (extend its timeout). + + Arguments: + message_id -- The ID of the message to be touched. + """ + + url = "queues/%s/messages/%s/touch" % (self.name, message_id) + result = self.client.post(url) + return result["body"] + + + def release(self, message_id): + """Executes an HTTP request to release a message (push a previously popped message back on the queue). + + Arguments: + message_id -- The ID of the message to be released. + """ + + url = "queues/%s/messages/%s/release" % (self.name, message_id) + result = self.client.post(url) + return result["body"] class IronMQ: From 512462933db4c3b7a6d65ee9b45012a40fa0bfce Mon Sep 17 00:00:00 2001 From: iHuman0x60 Date: Wed, 27 Feb 2013 13:32:52 +0400 Subject: [PATCH 7/7] Peek documentation updated --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7752133..267c81f 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ queue.post(*[str(i) for i in range(10)]) queue.get() ``` This will pop a message off the queue and return its body (aka a string) -In order to find out its attributes, use the following syntax: +In order to obtain its attributes, use the following syntax: ```python message = queue.get(verbose=True) @@ -140,7 +140,11 @@ Releasing a reserved message unreserves the message and puts it back on the queu ### **Peek** at a message: ```python -queue.peek() +message = queue.peek() +``` +or +```python +message = queue.peek(verbose=True) ``` Use this instead of Get if you wish the message to remain on the queue.