~ihabunek/triglav

ref: 5725e4080922882af88029a2e7dffdfc2f1b9911 triglav/lib/mix/tasks/triglav/import_zet.ex -rw-r--r-- 999 bytes
5725e408Ivan Habunek Validate and regenerate derived data after update 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
33
34
35
36
defmodule Mix.Tasks.Triglav.ImportZet do
  use Mix.Task

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

  require Logger

  @shortdoc "Imports GTFS data for ZET routes"

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

    {opts, _} = OptionParser.parse!(args, strict: [force: :boolean])

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

      {:ok, {:updated_to, feed}} ->
        Logger.info("Updated to #{feed.version} #{feed.start_date} #{feed.end_date}")

        Logger.info("Regenerating derived data")
        PublicTransport.generate()

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

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