LabCleaningBot: better error handling in create_or_update_task_group()
This commit is contained in:
parent
22911eae50
commit
7eb5d71e4e
21
main.py
21
main.py
@ -401,7 +401,7 @@ If due to any reason you can not participate, please just change your "👍" rea
|
|||||||
|
|
||||||
print(emoji, "direct", source, isRemove)
|
print(emoji, "direct", source, isRemove)
|
||||||
|
|
||||||
def create_or_update_task_group(self, task: Task) -> Result[str, str]:
|
def create_or_update_task_group(self, task: Task) -> Result[None, str]:
|
||||||
chatgroup = task.chatgroup
|
chatgroup = task.chatgroup
|
||||||
|
|
||||||
# Check if the group still exists
|
# Check if the group still exists
|
||||||
@ -423,8 +423,16 @@ If due to any reason you can not participate, please just change your "👍" rea
|
|||||||
chatgroup = create_result.unwrap().id
|
chatgroup = create_result.unwrap().id
|
||||||
|
|
||||||
task.chatgroup = chatgroup
|
task.chatgroup = chatgroup
|
||||||
self.api.update_group_members(chatgroup, [r.user.name for r in task.accepted_requests()])
|
|
||||||
self.api.update_group_admins(chatgroup, [r.user.name for r in task.accepted_requests()])
|
update_members_result = self.api.update_group_members(chatgroup, [r.user.name for r in task.accepted_requests()])
|
||||||
|
if is_err(update_members_result):
|
||||||
|
return Err(update_members_result.unwrap_err())
|
||||||
|
|
||||||
|
update_group_admins = self.api.update_group_admins(chatgroup, [r.user.name for r in task.accepted_requests()])
|
||||||
|
if is_err(update_group_admins):
|
||||||
|
return Err(update_group_admins.unwrap_err())
|
||||||
|
|
||||||
|
return Ok(None)
|
||||||
|
|
||||||
async def sync_members_and_tasks(self, session: Session):
|
async def sync_members_and_tasks(self, session: Session):
|
||||||
# Async routine that syncs active members using sync_members_as_active_users(),
|
# Async routine that syncs active members using sync_members_as_active_users(),
|
||||||
@ -442,6 +450,11 @@ If due to any reason you can not participate, please just change your "👍" rea
|
|||||||
print(sync_result.unwrap_err())
|
print(sync_result.unwrap_err())
|
||||||
|
|
||||||
for task in get_active_tasks(session, now()):
|
for task in get_active_tasks(session, now()):
|
||||||
|
create_or_update_result = self.create_or_update_task_group(task)
|
||||||
|
if is_err(create_or_update_result):
|
||||||
|
print(create_or_update_result.unwrap_err())
|
||||||
|
continue
|
||||||
|
|
||||||
reqs = task.create_additional_requests(now(), session)
|
reqs = task.create_additional_requests(now(), session)
|
||||||
|
|
||||||
if is_err(reqs):
|
if is_err(reqs):
|
||||||
@ -482,8 +495,6 @@ You have time to answer for {format_seconds(task.timeout)}."""
|
|||||||
recipients=[request.user.name])
|
recipients=[request.user.name])
|
||||||
res = self.api.send_message(message)
|
res = self.api.send_message(message)
|
||||||
|
|
||||||
self.create_or_update_task_group(task)
|
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user