Skip to content

Commit

Permalink
Use JSONDataEncoder to encode task createdDate
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sevein committed May 24, 2024
1 parent 4c11d3d commit 11c72fa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/MCPClient/lib/client/gearman.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import functools
import logging
import multiprocessing
from datetime import datetime

import gearman
from client import metrics
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/MCPServer/lib/server/tasks/backends/gearman_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion tests/MCPServer/test_gearman.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit 11c72fa

Please sign in to comment.