Skip to content

Commit

Permalink
Also pass the message id in the context. This can allow the server to…
Browse files Browse the repository at this point in the history
… detect if the message is being sent again, b/c the message had a visibility time out on a different worker.
  • Loading branch information
jhorman committed Jul 18, 2019
1 parent fb8cce3 commit ac3e34b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pyqs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ class TaskContext(object):
""" Tasks may optionally accept a _context variable. If they do, an
instance of this object is passed as the context. """

def __init__(self, conn, queue_url, receipt_handle):
def __init__(self, conn, queue_url, message_id, receipt_handle):
self.conn = conn
self.queue_url = queue_url
self.message_id = message_id
self.receipt_handle = receipt_handle

def change_message_visibility(self, timeout=timedelta(minutes=10)):
Expand Down
2 changes: 2 additions & 0 deletions pyqs/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def process_message(self):
full_task_path = message_body['task']
args = message_body['args']
kwargs = message_body['kwargs']
message_id = message['MessageId']
receipt_handle = message['ReceiptHandle']

task_name = full_task_path.split(".")[-1]
Expand All @@ -201,6 +202,7 @@ def process_message(self):
kwargs['_context'] = TaskContext(
conn=self.conn,
queue_url=queue_url,
message_id=message_id,
receipt_handle=receipt_handle
)

Expand Down

0 comments on commit ac3e34b

Please sign in to comment.