diff --git a/server/fishtest/rundb.py b/server/fishtest/rundb.py index 3fc66945c..9a3ecf4a6 100644 --- a/server/fishtest/rundb.py +++ b/server/fishtest/rundb.py @@ -1033,7 +1033,7 @@ def sync_request_task(self, worker_info): if w["blocked"]: # updates last_updated self.workerdb.update_worker( - my_name, blocked=w["blocked"], message=w["message"], username=None + my_name, blocked=w["blocked"], message=None, username=None ) error = self.blocked_worker_message(my_name, w["message"], host_url) return {"task_waiting": False, "error": error} diff --git a/server/fishtest/schemas.py b/server/fishtest/schemas.py index 45ed5db4c..f6fc3746b 100644 --- a/server/fishtest/schemas.py +++ b/server/fishtest/schemas.py @@ -105,8 +105,16 @@ def size_is_length(x): "_id?": ObjectId, "worker_name": short_worker_name, "blocked": bool, - "message": worker_message, + "message?": worker_message, # old field, todo: remove this field from db records if exists + "notes?": intersect( + [ + {"time": datetime_utc, "username": username, "message": worker_message}, + ..., + ], + size(0, 100), # new field, todo: add this field to the db records if it doesn't exists + ), "last_updated": datetime_utc, + at_least_one_of("message", "notes"), } diff --git a/server/fishtest/templates/workers.mak b/server/fishtest/templates/workers.mak index e16e36922..66d966869 100644 --- a/server/fishtest/templates/workers.mak +++ b/server/fishtest/templates/workers.mak @@ -66,14 +66,20 @@
Last changed: ${delta_date(diff_date(last_updated)) if last_updated is not None else "Never"}
- % if message: - - + % if notes and len(notes) > 0: + + % endif diff --git a/server/fishtest/views.py b/server/fishtest/views.py index d2a44c53f..048900886 100644 --- a/server/fishtest/views.py +++ b/server/fishtest/views.py @@ -202,7 +202,7 @@ def workers(request): w["body"] = worker_email( w["worker_name"], blocker_name, - w["message"], + w.get("notes", [{}])[-1].get("message", "No message available"), request.host_url, w["blocked"], ) @@ -275,7 +275,7 @@ def workers(request): "show_admin": True, "worker_name": worker_name, "blocked": w["blocked"], - "message": w["message"], + "notes": w.get("notes", []), "show_email": is_approver, "last_updated": w["last_updated"], "blocked_workers": blocked_workers, diff --git a/server/fishtest/workerdb.py b/server/fishtest/workerdb.py index 5839aec2e..03c1d0685 100644 --- a/server/fishtest/workerdb.py +++ b/server/fishtest/workerdb.py @@ -30,20 +30,28 @@ def get_worker( def update_worker(self, worker_name, blocked=None, message=None, username=None): current_worker = self.get_worker(worker_name) - new_message = message - if message and current_worker and current_worker.get("message") != message: - timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S %Z") - new_message = ( - f"{current_worker['message']}\n{username} {timestamp}\n{message}\n" - ) + new_note = None + if message: + time = datetime.now(timezone.utc) + new_note = { + "time": time, + "username": username, + "message": message, + } + + if current_worker: + notes = current_worker.get("notes", []) + if new_note: + notes.append(new_note) + else: + notes = [new_note] if new_note else [] r = { "worker_name": worker_name, "blocked": blocked, - "message": new_message, + "notes": notes, "last_updated": datetime.now(timezone.utc), } - validate(worker_schema, r, "worker") # may throw exception self.workers.replace_one({"worker_name": worker_name}, r, upsert=True)