Skip to content

Commit

Permalink
Enhance blocking workers flow
Browse files Browse the repository at this point in the history
* Old messages become immutable
* The message is required thus explaining more the reason why would an approver/the same user unblock/block.
* Full history of the blocking notes
* automatic inclusion for timestamp and blocker name
  • Loading branch information
peregrineshahin committed Jul 7, 2024
1 parent 12981ff commit c1233cb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 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"]
my_name, blocked=w["blocked"], message=w["message"], username=None
)
error = self.blocked_worker_message(my_name, w["message"], host_url)
return {"task_waiting": False, "error": error}
Expand Down
28 changes: 26 additions & 2 deletions server/fishtest/templates/workers.mak
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,24 @@
<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">
<label for="messageInput" class="form-label">Issue</label>
% if message:
<label for="messageView" class="form-label">Issues</label>
<textarea
id="messageView"
rows="6"
class="form-control mb-4"
readonly
>${message}</textarea>
% endif

<label for="messageInput" class="form-label">New Notes</label>
<textarea
id="messageInput"
name="message"
rows="4" class="form-control"
placeholder="Describe the issue here" name="message"
>${message}</textarea>
required
></textarea>
</div>
<div class="mb-3 form-check">
<label class="form-check-label" for="blockWorker">Blocked</label>
Expand Down Expand Up @@ -148,3 +160,15 @@
% endif
</tbody>
</table>


<script>
async function handleScrollTextArea () {
await DOMContentLoaded();
const messageView = document.getElementById('messageView');
if (messageView) {
messageView.scrollTop = messageView.scrollHeight;
}
}
handleScrollTextArea();
</script>
10 changes: 9 additions & 1 deletion server/fishtest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,17 @@ def workers(request):
)
message = message[:max_chars]
message = normalize_lf(message)
if message.strip() == "":
request.session.flash(
"A new message is required for unblocking/blocking workers", "error"
)
return home(request)
was_blocked = request.workerdb.get_worker(worker_name)["blocked"]
request.rundb.workerdb.update_worker(
worker_name, blocked=blocked, message=message
worker_name,
blocked=blocked,
message=message,
username=blocker_name,
)
if blocked != was_blocked:
request.session.flash(
Expand Down
14 changes: 12 additions & 2 deletions server/fishtest/workerdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,23 @@ def get_worker(
else:
return r

def update_worker(self, worker_name, blocked=None, message=None):
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"
)

r = {
"worker_name": worker_name,
"blocked": blocked,
"message": message,
"message": new_message,
"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 c1233cb

Please sign in to comment.