queues #19

Merged
emmatveev merged 13 commits from queues into master 2024-11-27 02:46:59 +03:00
Showing only changes of commit 292bacc963 - Show all commits

View File

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