From 988cb767798b7755b4a1c1130d32d14a45b10bae Mon Sep 17 00:00:00 2001 From: Sourour Benzarti Date: Mon, 1 Jul 2024 18:36:18 +0200 Subject: [PATCH 1/2] return updated rowcount when completing a task --- postgrestq/task_queue.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/postgrestq/task_queue.py b/postgrestq/task_queue.py index f9c8def..be7922a 100644 --- a/postgrestq/task_queue.py +++ b/postgrestq/task_queue.py @@ -394,7 +394,7 @@ def get_many(self, amount: int) -> Sequence[ conn.commit() return ret - def complete(self, task_id: Optional[UUID]) -> None: + def complete(self, task_id: Optional[UUID]) -> int: """Mark a task as completed. Marks a task as completed by setting completed_at column by @@ -409,20 +409,31 @@ def complete(self, task_id: Optional[UUID]) -> None: task_id : UUID | None the task ID + Returns + ------- + the number of updated rows: int + """ logger.info(f"Marking task {task_id} as completed") conn = self.conn + count = 0 with conn.cursor() as cur: cur.execute( sql.SQL( """ UPDATE {} SET completed_at = current_timestamp - WHERE id = %s""" + WHERE id = %s + AND completed_at is NULL""" ).format(sql.Identifier(self._table_name)), (task_id,), ) + count = cur.rowcount + if count == 0: + logger.info(f"Task {task_id} was already completed") + conn.commit() + return count def is_empty(self) -> bool: """Check if the task queue is empty. From 0dd9ee427903c02fcf807d8dcaa376be50d7f220 Mon Sep 17 00:00:00 2001 From: Jacopo Farina Date: Tue, 2 Jul 2024 11:15:19 +0200 Subject: [PATCH 2/2] Prepare for release 1.1.0 --- CHANGELOG.md | 4 ++++ pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65b9203..55062c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.1.0 - 2024-07-01 + +* The `complete()` method now returns the count of updated tasks, 0 if it was already completed + ## 1.0.1 - 2024-05-27 * Restrict the type yielded by the generator to never be None diff --git a/pyproject.toml b/pyproject.toml index 0bf25b6..3c52d47 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ log_cli_date_format = "%Y-%m-%d %H:%M:%S" [project] name = "postgres-tq" -version = "1.0.1" +version = "1.1.0" description = "Postgres Based Task Queue" authors = [ {name = "FlixTech", email = "open-source@flixbus.com"},