neiam
/apollos_crib
It's Apollo's Crib
public · Issues · Pulls 1 · Labels · Forks · Compare · Actions failure · Badges · Packages
Log in to mark this repository.
Refresh station counts every five minutes, not every day
ed1ce38 · Gabriel Morell · 2026-09-04 18:21
Message
{commit_body(@commit)}
Files changed
modified
?
+0
−0
Binary file — not rendered.
modified
?
+0
−0
Binary file — not rendered.
modified
apps/room_gbfs/lib/room_gbfs/gbfs_worker.ex
+50
−35
| 13 | 13 | |
| 14 | 14 | # 1d |
| 15 | 15 | @static_refresh_seconds 86400 |
| 16 | − @static_delay_seconds 600 | |
| 16 | + | |
| 17 | + # Ten hours, and it always was: this went to `:timer.minutes/1` while being | |
| 18 | + # called seconds. Left where it is now that the counts refresh on the five | |
| 19 | + # minute pass -- what the static pass still carries is station locations and | |
| 20 | + # vehicle types, which do not change between one day and the next -- but | |
| 21 | + # named for what it does. | |
| 22 | + @static_delay_minutes 600 | |
| 17 | 23 | |
| 18 | 24 | def start_link(opts) do |
| 19 | 25 | GenServer.start_link(__MODULE__, opts, name: via_tuple("gbfs" <> opts[:name])) |
| 30 | 36 | Periodic.start_link( |
| 31 | 37 | every: :timer.seconds(@static_refresh_seconds), |
| 32 | 38 | run: fn -> RoomGbfs.Worker.update_static_data(opts[:name]) end, |
| 33 | − initial_delay: :timer.minutes(@static_delay_seconds) | |
| 39 | + initial_delay: :timer.minutes(@static_delay_minutes) | |
| 34 | 40 | ) |
| 35 | 41 | |
| 36 | 42 | {:ok, %{id: opts[:name], inst: nil}} |
| 483 | 489 | {:ok, result} -> |
| 484 | 490 | case result.body |> Poison.decode() do |
| 485 | 491 | {:ok, json_body} -> |
| 486 | − if json_body["data"] | |
| 487 | − |> Map.has_key?(cfg.config.lang) do | |
| 488 | − bcast(state.id, :parsing, 2, 5) | |
| 489 | − | |
| 490 | − json_body["data"][cfg.config.lang]["feeds"] | |
| 491 | − |> Enum.map(fn %{"name" => name, "url" => url} -> | |
| 492 | − case name do | |
| 493 | − "station_information" -> | |
| 494 | − write_data(url, :stat_info, state.id, cfg.config.lang) | |
| 495 | − bcast(state.id, :system_information, 3, 5) | |
| 496 | − | |
| 497 | − "ebikes_at_stations" -> | |
| 498 | − write_data(url, :ebikes_at_stations, state.id, cfg.config.lang) | |
| 499 | − bcast(state.id, :system_information, 4, 5) | |
| 500 | − | |
| 501 | − "free_bike_status" -> | |
| 502 | − write_data(url, :free_bike, state.id, cfg.config.lang) | |
| 503 | − bcast(state.id, :system_information, 5, 5) | |
| 504 | − | |
| 505 | − _otherwise -> | |
| 506 | − :ok | |
| 507 | − end | |
| 508 | − end) | |
| 509 | − | |
| 510 | − {:noreply, state} | |
| 511 | − else | |
| 512 | − bcast( | |
| 513 | − state.id, | |
| 514 | − :language_error, | |
| 515 | − "Invalid Language Selected, available #{json_body["data"] |> Map.keys() |> Enum.join(", ")}, selected: #{cfg.config.lang}" | |
| 516 | − ) | |
| 517 | − | |
| 518 | − {:noreply, state} | |
| 492 | + case RoomGbfs.V3.feeds(json_body, cfg.config.lang) do | |
| 493 | + {:ok, _version, feeds} -> | |
| 494 | + bcast(state.id, :parsing, 2, 5) | |
| 495 | + | |
| 496 | + feeds | |
| 497 | + |> Enum.sort_by(&RoomGbfs.V3.feed_order/1) | |
| 498 | + |> Enum.map(fn %{"name" => name, "url" => url} -> | |
| 499 | + case RoomGbfs.V3.feed_name(name) do | |
| 500 | + "station_information" -> | |
| 501 | + write_data(url, :stat_info, state.id, cfg.config.lang) | |
| 502 | + bcast(state.id, :system_information, 3, 5) | |
| 503 | + | |
| 504 | + # The counts. Fetched here rather than only on the | |
| 505 | + # daily static pass, which is how a dock could report | |
| 506 | + # yesterday's bikes for a whole day. | |
| 507 | + "station_status" -> | |
| 508 | + write_data(url, :stat_status, state.id, cfg.config.lang) | |
| 509 | + bcast(state.id, :system_information, 4, 5) | |
| 510 | + | |
| 511 | + "ebikes_at_stations" -> | |
| 512 | + write_data(url, :ebikes_at_stations, state.id, cfg.config.lang) | |
| 513 | + bcast(state.id, :system_information, 4, 5) | |
| 514 | + | |
| 515 | + "free_bike_status" -> | |
| 516 | + write_data(url, :free_bike, state.id, cfg.config.lang) | |
| 517 | + bcast(state.id, :system_information, 5, 5) | |
| 518 | + | |
| 519 | + _otherwise -> | |
| 520 | + :ok | |
| 521 | + end | |
| 522 | + end) | |
| 523 | + | |
| 524 | + {:noreply, state} | |
| 525 | + | |
| 526 | + {:error, languages} -> | |
| 527 | + bcast( | |
| 528 | + state.id, | |
| 529 | + :language_error, | |
| 530 | + "Invalid Language Selected, available #{Enum.join(languages, ", ")}, selected: #{cfg.config.lang}" | |
| 531 | + ) | |
| 532 | + | |
| 533 | + {:noreply, state} | |
| 519 | 534 | end |
| 520 | 535 | |
| 521 | 536 | {:error, error} -> |
Parents: 0a726e7