Skip to content

Commit 5fd09a1

Browse files
authored
Log event when Workspace details posted (#55)
* Log event when Workspace details posted * bump version
1 parent 1f06045 commit 5fd09a1

File tree

2 files changed

+44
-27
lines changed

2 files changed

+44
-27
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.8.12
1+
0.8.13

src/boardwalkd/server.py

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -391,42 +391,34 @@ class WorkspaceCatchHandler(UIBaseHandler):
391391
def post(self, workspace: str):
392392
try:
393393
state.workspaces[workspace].semaphores.caught = True
394-
395-
# Record who clicked the catch button
396-
cur_user = self.current_user.decode()
397-
payload = {
398-
"severity": "info",
399-
"message": f"Workspace caught by {cur_user}",
400-
}
401-
event = WorkspaceEvent.parse_obj(payload)
402-
event.received_time = datetime.utcnow()
403-
state.workspaces[workspace].events.append(event)
404-
405-
state.flush()
406-
return self.render("index_workspace_release.html", workspace_name=workspace)
407394
except KeyError:
408395
return self.send_error(404)
409396

397+
# Record who clicked the catch button
398+
cur_user = self.current_user.decode()
399+
event = WorkspaceEvent(
400+
severity="info", message=f"Workspace caught by {cur_user}"
401+
)
402+
internal_workspace_event(workspace, event)
403+
404+
return self.render("index_workspace_release.html", workspace_name=workspace)
405+
410406
@tornado.web.authenticated
411407
def delete(self, workspace: str):
412408
try:
413409
state.workspaces[workspace].semaphores.caught = False
414-
415-
# Record who clicked the release button
416-
cur_user = self.current_user.decode()
417-
payload = {
418-
"severity": "info",
419-
"message": f"Workspace released by {cur_user}",
420-
}
421-
event = WorkspaceEvent.parse_obj(payload)
422-
event.received_time = datetime.utcnow()
423-
state.workspaces[workspace].events.append(event)
424-
425-
state.flush()
426-
return self.render("index_workspace_catch.html", workspace_name=workspace)
427410
except KeyError:
428411
return self.send_error(404)
429412

413+
# Record who clicked the release button
414+
cur_user = self.current_user.decode()
415+
event = WorkspaceEvent(
416+
severity="info", message=f"Workspace released by {cur_user}"
417+
)
418+
internal_workspace_event(workspace, event)
419+
420+
return self.render("index_workspace_catch.html", workspace_name=workspace)
421+
430422

431423
class WorkspaceEventsHandler(UIBaseHandler):
432424
"""Handles serving workspace events in the UI"""
@@ -682,6 +674,18 @@ def post(self, workspace: str):
682674
state.workspaces[workspace].last_seen = datetime.utcnow()
683675
state.flush()
684676

677+
# Log the updated details to the events table
678+
workspace_details = state.workspaces[workspace].details
679+
message = (
680+
"Workspace client details:"
681+
f" Workflow: {workspace_details.workflow},"
682+
f" Worker: {workspace_details.worker_username}@{workspace_details.worker_hostname},"
683+
f" Host Pattern: {workspace_details.host_pattern},"
684+
f" Command: {workspace_details.worker_command}"
685+
)
686+
event = WorkspaceEvent(severity="info", message=message)
687+
internal_workspace_event(workspace, event)
688+
685689

686690
class WorkspaceHeartbeatApiHandler(APIBaseHandler):
687691
"""Handles receiving heartbeats from workers"""
@@ -815,6 +819,19 @@ def log_request(handler: tornado.web.RequestHandler):
815819
)
816820

817821

822+
def internal_workspace_event(workspace: str, event: WorkspaceEvent):
823+
"""
824+
Appends an internally-generated workspace event to the state and logs to the
825+
application log
826+
"""
827+
event.received_time = datetime.utcnow()
828+
state.workspaces[workspace].events.append(event)
829+
app_log.info(
830+
f"internal_workspace_event: {workspace} {event.severity} {event.message}"
831+
)
832+
state.flush()
833+
834+
818835
def make_app(
819836
auth_expire_days: float,
820837
auth_method: str,

0 commit comments

Comments
 (0)