Compare commits

..

No commits in common. "5fd8147ff3658649498084e04441812e866d8741" and "adc2525fabd561610421b75725347c255e9e24da" have entirely different histories.

View File

@ -18,22 +18,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):