Compare commits

..

No commits in common. "b150f2fafc1da942db32fc7b690366241299fc44" and "f8ec8af981d635b1d79bae84dc7fde7eb4599bcc" have entirely different histories.

View File

@ -17,22 +17,22 @@ class QueuesException(Exception):
class TasksHandlerMixin: class TasksHandlerMixin:
def poll(self): def poll(self):
while True: while True:
response = requests.get(f'{QUEUES_URL}/api/v1/take', headers={'queue': self.queue_name}).json() response = requests.get(f'{QUEUES_URL}/api/v1/take', headers={'queue': self.queue_name})
task = response.get('task') if response.status_code == 404:
if not task:
time.sleep(0.2) time.sleep(0.2)
continue continue
data = response.json()
try: try:
self.process(task['payload']) self.process(data['payload'])
except Exception as exc: except Exception as exc:
print(f'Error processing message id={task["id"]}, payload={task["payload"]}, exc={exc}') print(f'Error processing message id={data["id"]}, payload={data["payload"]}, exc={exc}')
continue continue
try: try:
resp = requests.post(f'{QUEUES_URL}/api/v1/finish', json={'id': task['id']}) resp = requests.post(f'{QUEUES_URL}/api/v1/finish', json={'id': data['id']})
if resp.status_code != 202: if resp.status_code != 202:
raise QueuesException raise QueuesException
except: except:
print(f'Failed to finish task id={task["id"]}') print(f'Failed to finish task id={data["id"]}')
@property @property
def queue_name(self): def queue_name(self):