From 11c72fa9542be92dd00e8cea97dfe095a77e6654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Garc=C3=ADa=20Crespo?= Date: Sat, 27 Apr 2024 05:06:15 +0000 Subject: [PATCH] Use JSONDataEncoder to encode task createdDate This commit modifies the MCPServer to encode the `createdDate` of tasks using `datetime` which is natively supported by our JSONDataEncoder. The conversion to the METS-compliant format now occurs during the decoding process on the client side. This change ensures consistent use of RFC 3339 format across all communications. --- src/MCPClient/lib/client/gearman.py | 10 +++++++++- .../lib/server/tasks/backends/gearman_backend.py | 2 +- tests/MCPServer/test_gearman.py | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/MCPClient/lib/client/gearman.py b/src/MCPClient/lib/client/gearman.py index f45ed9bbe1..d36053a1f5 100644 --- a/src/MCPClient/lib/client/gearman.py +++ b/src/MCPClient/lib/client/gearman.py @@ -1,6 +1,7 @@ import functools import logging import multiprocessing +from datetime import datetime import gearman from client import metrics @@ -66,9 +67,16 @@ def _prepare_jobs(task_name, gearman_job): jobs = [] for task_uuid, task_data in tasks.items(): + # We use ISO 8601 in our wire format but replace the `T` separator + # with a space for METS compatibility in client scripts. + created_date = datetime.fromisoformat(task_data["createdDate"]).isoformat( + " " + ) arguments = str(task_data["arguments"]) arguments = replace_task_arguments( - arguments, task_uuid, task_data.get("createdDate") + arguments, + task_uuid, + created_date, ) arguments = parse_command_line(arguments) diff --git a/src/MCPServer/lib/server/tasks/backends/gearman_backend.py b/src/MCPServer/lib/server/tasks/backends/gearman_backend.py index 8ef0b4a181..f55b89d8c9 100644 --- a/src/MCPServer/lib/server/tasks/backends/gearman_backend.py +++ b/src/MCPServer/lib/server/tasks/backends/gearman_backend.py @@ -190,7 +190,7 @@ def failed(self): def serialize_task(self, task): return { "uuid": str(task.uuid), - "createdDate": task.start_timestamp.isoformat(" "), + "createdDate": task.start_timestamp, "arguments": task.arguments, "wants_output": task.wants_output, } diff --git a/tests/MCPServer/test_gearman.py b/tests/MCPServer/test_gearman.py index 63195b75ed..ca8fab26f8 100644 --- a/tests/MCPServer/test_gearman.py +++ b/tests/MCPServer/test_gearman.py @@ -39,7 +39,7 @@ def format_gearman_request(tasks): task_uuid = str(task.uuid) request["tasks"][task_uuid] = { "uuid": task_uuid, - "createdDate": task.start_timestamp.isoformat(" "), + "createdDate": task.start_timestamp, "arguments": task.arguments, "wants_output": task.wants_output, }