Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SSE background updates for Field Reports #1498

Closed
srabraham opened this issue Jan 6, 2025 · 3 comments
Closed

Implement SSE background updates for Field Reports #1498

srabraham opened this issue Jan 6, 2025 · 3 comments
Assignees

Comments

@srabraham
Copy link
Member

srabraham commented Jan 6, 2025

We've never actually had SSEs set up for Field Reports, as I observed here:

// TODO: this will never receive any events currently, since the server isn't configured to
// fire events for FieldReports. See
// https://github.com/burningmantech/ranger-ims-server/blob/954498eb125bb9a83d2b922361abef4935f228ba/src/ims/application/_eventsource.py#L113-L135
eventSource.addEventListener("FieldReport", function(e) {
const send = new BroadcastChannel(fieldReportChannelName);
send.postMessage(JSON.parse(e.data));
}, true);

and that's because this "if-else" doesn't have an "else if" case for FieldReport:

if eventClass is Incident:
incident = loggerEvent.get("incident", None)
if incident is None:
incidentNumber = loggerEvent.get("incidentNumber", None)
eventName = loggerEvent.get("eventID", "")
else:
incidentNumber = incident.number
eventName = incident.eventID
if incidentNumber is None:
self._log.critical(
"Unable to determine incident number from store event: {event}",
event=loggerEvent,
)
return None
message = {
"event_id": eventName,
"incident_number": incidentNumber,
}
else:
self._log.critical(
"Unknown data store event class {eventClass} sent event: {event}",
eventClass=eventClass,
event=loggerEvent,
)

@srabraham srabraham self-assigned this Jan 6, 2025
@srabraham
Copy link
Member Author

There are a few subtleties here that make me more nervous about implementing SSEs for Field Reports than for Incidents.

  1. This would increase the number of SSE calls on playa, i.e. since anyone with writeFieldReports permission would start having an SSE too (previously it'd just be people with writeIncident or readIncident). Load problem? Probably not, but who knows for sure.
  2. I made a sweet optimization today to the Incidents page, so that it only updates data on a per-Incident basis based on SSEs (rather than always updating the entire page). That optimization doesn't carry over perfectly to the Field Reports page, since Rangers with limited IMS access (i.e. most Rangers) get 403 errors when they try to access FRs to which they don't have access. Those 403s end up showing as JS errors in the web browser, and there seems to be no good way to prevent that. It's ugly seeing constant errors!

I may work on the first point above by having an IMS page automatically redirect a page to the IMS homescreen when the user is logged out. That'd end the open SSE connection.

@srabraham
Copy link
Member Author

srabraham commented Jan 23, 2025

With #1523 in place, we're now updating the Field Reports and Field Report pages on any updates to a Field Report.

Here's where we are:

Here's where I might take this next:

  • Update Incident page when an FR currently attached to that incident has been updated
  • Update Incident page when any FR is updated, but just update that one FR, don't fetch all (for efficiency)

And this is an option, but not one I'm considering all that strongly:

  • Update the Incidents page's indexed list of FRs anytime any FR changes (this would require a fair bit of background work on any FR update, and it would be done solely to feed the text-search feature. IMO the cost might outweigh the benefits)

srabraham added a commit that referenced this issue Jan 23, 2025
This keeps the Incident page fully up-to-date with changes on the
server to Field Reports. It does this in a selective manner, just
loading the particular FR that was changed.

#1498
srabraham added a commit that referenced this issue Jan 23, 2025
This keeps the Incident page fully up-to-date with changes on the
server to Field Reports. It does this in a selective manner, just
loading the particular FR that was changed.

#1498
@srabraham
Copy link
Member Author

I'm ready to call this done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant