Skip to content

Commit

Permalink
vdbergh suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
peregrineshahin committed Jul 27, 2024
1 parent c1233cb commit da13efb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 20 deletions.
2 changes: 1 addition & 1 deletion server/fishtest/rundb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
10 changes: 9 additions & 1 deletion server/fishtest/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}


Expand Down
22 changes: 14 additions & 8 deletions server/fishtest/templates/workers.mak
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,20 @@
<form method="POST">
<div class="mb-3">Last changed: ${delta_date(diff_date(last_updated)) if last_updated is not None else "Never"}</div>
<div class="mb-3">
% if message:
<label for="messageView" class="form-label">Issues</label>
<textarea
id="messageView"
rows="6"
class="form-control mb-4"
readonly
>${message}</textarea>
% if notes and len(notes) > 0:
<label for="messageView" class="form-label">Notes</label>
<textarea
id="messageView"
rows="7"
class="form-control mb-4"
readonly
>
% for note in notes:
${note["username"]} ${note["time"].strftime("%Y-%m-%d %H:%M:%S %Z")}
${note["message"]}

% endfor
</textarea>
% endif

<label for="messageInput" class="form-label">New Notes</label>
Expand Down
4 changes: 2 additions & 2 deletions server/fishtest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 16 additions & 8 deletions server/fishtest/workerdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit da13efb

Please sign in to comment.