~ihabunek/triglav

ref: a128d7b3324bfe05384eab5648bf55e8df32a7c1 triglav/lib/mix/tasks/triglav/osmosis_update.ex -rw-r--r-- 886 bytes
a128d7b3Ivan Habunek Better naming for matched/unmatched routes 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
defmodule Mix.Tasks.Triglav.OsmosisUpdate do
  use Mix.Task

  alias Triglav.Derived.PublicTransport
  alias Mix.Tasks.Triglav.ValidateRoutes

  require Logger

  @shortdoc "Updates the osmosis data to latest available."

  @impl Mix.Task
  def run(_args) do
    Application.put_env(:triglav, :repo_only, true)
    {:ok, _} = Application.ensure_all_started(:triglav)

    case Triglav.Import.Osmosis.update() do
      {:ok, :no_update_available} ->
        Logger.info("Done. No update available")

      {:ok, {:updated_to, state}} ->
        Logger.info("Updated to #{state.sequence_no} #{state.timestamp}")
        Logger.info("Regenerating derived data")
        PublicTransport.generate()

        Logger.info("Running validator")
        ValidateRoutes.validate_routes()

      {:error, error} ->
        Logger.error("Update failed. Error:\n#{inspect(error)}")
    end
  end
end