-
Notifications
You must be signed in to change notification settings - Fork 0
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
Poll alerts #1291
Conversation
There was a problem hiding this 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!
lib/signs_ui/alerts/state.ex
Outdated
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 |
There was a problem hiding this comment.
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)
"filter[route_type]" => "0,1" | ||
} | ||
) do | ||
{:ok, %HTTPoison.Response{status_code: 200, body: body}} -> |
There was a problem hiding this comment.
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)]) |
There was a problem hiding this comment.
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.
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.