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

Poll alerts #1291

Merged
merged 11 commits into from
Nov 29, 2023
Merged

Poll alerts #1291

merged 11 commits into from
Nov 29, 2023

Conversation

PaulJKim
Copy link
Collaborator

Summary of changes

Asana Ticket: Rework Signs UI to direct poll for alert events

Replace the use of GenStage and Server Sent Events with polling the V3 API every 5 seconds for alerts data. With SSE, the events occasionally would stop coming through for a reason we were not able to pin down. Since Signs UI doesn't need to be fully "real-time", swapping out SSE for some simple polling should be more straightforward and reliable.

@PaulJKim PaulJKim requested a review from panentheos November 27, 2023 21:18
@PaulJKim PaulJKim removed the request for review from panentheos November 27, 2023 21:34
@PaulJKim PaulJKim requested a review from panentheos November 27, 2023 21:51
Copy link
Collaborator

@panentheos panentheos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments, then looks good!

defp update_state(%Event{event: "add", data: data}, state) do
alert = Events.parse(data)
Map.put(state, alert.id, alert)
def parse(payload) when is_map(payload) do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Since these parse functions operate on different levels of the data structure, it might be slightly clearer to give them distinct names rather than implicitly differentiating by type. (And/or combine some of them)

lib/signs_ui/alerts/state.ex Outdated Show resolved Hide resolved
"filter[route_type]" => "0,1"
}
) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to load balancing/caching, the API can sometimes return slightly older data on subsequent calls, which means that unless we track Last-Modified, we could see this state briefly "out of order" around transitions. That's probably fine for this case, since this data doesn't change very often, and it only populates the form UI, but I wanted to call it out.

Display.format_state(new_state)
)

Logger.info(["alert_state_updated ", inspect(new_state)])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: This now logs every 5 seconds, regardless of whether there was a change. If we have any reports tied to this, we may need to update them.

@PaulJKim PaulJKim merged commit 7ebc258 into master Nov 29, 2023
1 check passed
@PaulJKim PaulJKim deleted the pk/poll-alerts branch November 29, 2023 19:53
PaulJKim added a commit that referenced this pull request Nov 29, 2023
@PaulJKim PaulJKim mentioned this pull request Nov 29, 2023
PaulJKim added a commit that referenced this pull request Nov 29, 2023
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

Successfully merging this pull request may close these issues.

2 participants