master #28
@ -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})
|
response = requests.get(f'{QUEUES_URL}/api/v1/take', headers={'queue': self.queue_name}).json()
|
||||||
if response.status_code == 404:
|
task = response.get('task')
|
||||||
|
if not task:
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
continue
|
continue
|
||||||
data = response.json()
|
|
||||||
try:
|
try:
|
||||||
self.process(data['payload'])
|
self.process(task['payload'])
|
||||||
except Exception as exc:
|
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
|
continue
|
||||||
try:
|
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:
|
if resp.status_code != 202:
|
||||||
raise QueuesException
|
raise QueuesException
|
||||||
except:
|
except:
|
||||||
print(f'Failed to finish task id={data["id"]}')
|
print(f'Failed to finish task id={task["id"]}')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def queue_name(self):
|
def queue_name(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user