From c4725e268505779e3d6739b6f3ea28a561c1886e Mon Sep 17 00:00:00 2001 From: lemoer Date: Fri, 27 Dec 2024 02:05:26 +0100 Subject: [PATCH] LabCleaningBot: check for timeouts --- main.py | 8 ++++++++ models.py | 2 ++ 2 files changed, 10 insertions(+) diff --git a/main.py b/main.py index 67b3621..e2f05a0 100644 --- a/main.py +++ b/main.py @@ -334,6 +334,14 @@ class LabCleaningBot: else: print(res.unwrap_err()) + # check for timeouts + for request in task.freshly_expired_requests(datetime.datetime.now()): + print("Request expired:", repr(request)) + message = SendMessageSimple( + message="You did not respond to the task request in time.", + recipients=[request.user.name]) + res = self.api.send_message(message) + session.commit() await asyncio.sleep(1) diff --git a/models.py b/models.py index 33b14b1..9020d1f 100644 --- a/models.py +++ b/models.py @@ -113,6 +113,8 @@ class Task(SQLModel, table=True): if maybe_timeout is not None: expired_requests.append(r) + return expired_requests + def create_additional_requests(self, now: datetime.datetime, session: Session) -> Result[List["ParticipationRequest"], List["ParticipationRequest"]]: additional_requests = []