Compare commits
11 Commits
queues
...
ce550c31f4
| Author | SHA1 | Date | |
|---|---|---|---|
| ce550c31f4 | |||
| ba2f1bb768 | |||
| 889a20609f | |||
| 1c3d1566e5 | |||
| 2b88479cec | |||
| 7238d725dd | |||
| 4a3fa3c2ab | |||
| 45e1c0fe8a | |||
| 989f7026ad | |||
| 90378be7c5 | |||
| 95e4f5e8da |
@@ -25,7 +25,4 @@ class Daemon(base.Daemon, queues.TasksHandlerMixin):
|
||||
reply_markup = payload.get('reply_markup')
|
||||
if reply_markup:
|
||||
body['reply_markup'] = reply_markup
|
||||
try:
|
||||
self.bot.send_message(**body, parse_mode='Markdown')
|
||||
except Exception as exc:
|
||||
print('Error', str(exc))
|
||||
|
||||
@@ -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}).json()
|
||||
task = response.get('task')
|
||||
if not task:
|
||||
response = requests.get(f'{QUEUES_URL}/api/v1/take', headers={'queue': self.queue_name})
|
||||
if response.status_code == 404:
|
||||
time.sleep(0.2)
|
||||
continue
|
||||
data = response.json()
|
||||
try:
|
||||
self.process(task['payload'])
|
||||
self.process(data['payload'])
|
||||
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
|
||||
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:
|
||||
raise QueuesException
|
||||
except:
|
||||
print(f'Failed to finish task id={task["id"]}')
|
||||
print(f'Failed to finish task id={data["id"]}')
|
||||
|
||||
@property
|
||||
def queue_name(self):
|
||||
|
||||
Reference in New Issue
Block a user