Skip to content

Commit

Permalink
Improve consolidations and seeding
Browse files Browse the repository at this point in the history
  • Loading branch information
altjohndev committed Jan 12, 2021
1 parent 995a6b6 commit 323d121
Show file tree
Hide file tree
Showing 34 changed files with 91 additions and 100 deletions.
4 changes: 2 additions & 2 deletions lib/health_board/contexts/seeder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule HealthBoard.Contexts.Seeder do

path
|> csv_copy_query(table_name, fields)
|> Repo.query!()
|> Repo.query!([], timeout: :infinity)

:ok
end
Expand All @@ -51,7 +51,7 @@ defmodule HealthBoard.Contexts.Seeder do

@spec down!(String.t()) :: :ok
def down!(table_name) do
Repo.query!("TRUNCATE #{table_name} CASCADE;")
Repo.query!("TRUNCATE #{table_name} CASCADE;", [], timeout: :infinity)
:ok
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ defmodule HealthBoard.Contexts.Seeders.YearlyPopulations do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ defmodule HealthBoard.Contexts.Seeders.DailyFluSyndromeCases do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ defmodule HealthBoard.Contexts.Seeders.MonthlyFluSyndromeCases do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ defmodule HealthBoard.Contexts.Seeders.PandemicFluSyndromeCases do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ defmodule HealthBoard.Contexts.Seeders.WeeklyFluSyndromeCases do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
2 changes: 1 addition & 1 deletion lib/health_board/contexts/seeders/geo/locations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule HealthBoard.Contexts.Seeders.Locations do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule HealthBoard.Contexts.Seeders.LocationsChildren do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule HealthBoard.Contexts.Seeders.DailyICURate do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
2 changes: 1 addition & 1 deletion lib/health_board/contexts/seeders/info/cards.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule HealthBoard.Contexts.Seeders.Cards do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
2 changes: 1 addition & 1 deletion lib/health_board/contexts/seeders/info/dashboards.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule HealthBoard.Contexts.Seeders.Dashboards do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
2 changes: 1 addition & 1 deletion lib/health_board/contexts/seeders/info/data_periods.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule HealthBoard.Contexts.Seeders.DataPeriods do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
2 changes: 1 addition & 1 deletion lib/health_board/contexts/seeders/info/groups.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule HealthBoard.Contexts.Seeders.Groups do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
2 changes: 1 addition & 1 deletion lib/health_board/contexts/seeders/info/indicators.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule HealthBoard.Contexts.Seeders.Indicators do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule HealthBoard.Contexts.Seeders.IndicatorsChildren do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule HealthBoard.Contexts.Seeders.IndicatorsSources do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
2 changes: 1 addition & 1 deletion lib/health_board/contexts/seeders/info/sections.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule HealthBoard.Contexts.Seeders.Sections do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
2 changes: 1 addition & 1 deletion lib/health_board/contexts/seeders/info/sections_cards.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule HealthBoard.Contexts.Seeders.SectionsCards do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule HealthBoard.Contexts.Seeders.SectionsCardsFilters do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
2 changes: 1 addition & 1 deletion lib/health_board/contexts/seeders/info/sources.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule HealthBoard.Contexts.Seeders.Sources do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
2 changes: 1 addition & 1 deletion lib/health_board/contexts/seeders/sars/daily_sars_cases.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ defmodule HealthBoard.Contexts.Seeders.DailySARSCases do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ defmodule HealthBoard.Contexts.Seeders.MonthlySARSCases do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ defmodule HealthBoard.Contexts.Seeders.PandemicSARSCases do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ defmodule HealthBoard.Contexts.Seeders.PandemicSARSSymptoms do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ defmodule HealthBoard.Contexts.Seeders.WeeklySARSCases do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule HealthBoard.Contexts.Seeders.DailyCOVIDReports do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule HealthBoard.Contexts.Seeders.MonthlyCOVIDReports do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule HealthBoard.Contexts.Seeders.PandemicCOVIDReports do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule HealthBoard.Contexts.Seeders.WeeklyCOVIDReports do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule HealthBoard.Contexts.Seeders.YearlyCOVIDReports do

@spec reseed!(String.t() | nil) :: :ok
def reseed!(base_path \\ nil) do
up!(base_path)
down!()
up!(base_path)
end

@spec up!(String.t() | nil) :: :ok
Expand Down
31 changes: 16 additions & 15 deletions lib/health_board/updaters/covid_reports_updater.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ defmodule HealthBoard.Updaters.CovidReportsUpdater do
@spec handle_info(atom, t()) :: {:noreply, t()}
# credo:disable-for-next-line Credo.Check.Refactor.CyclomaticComplexity
def handle_info(:update, %{status: status} = state) do
Logger.info("Update request received")
Logger.info("Update request received. Current status: #{inspect(status)}")

state =
if state.error? do
state = struct(state, error?: false, status: :idle)
state = struct(state, error?: false)

case status do
:fetching_header -> update_and_continue(state)
Expand All @@ -68,7 +68,9 @@ defmodule HealthBoard.Updaters.CovidReportsUpdater do
CovidReportsUpdater.Consolidator.init()
end

update_and_continue(state)
state
|> struct(status: :fetching_header)
|> update_and_continue()
end

{:noreply, state}
Expand Down Expand Up @@ -219,21 +221,20 @@ defmodule HealthBoard.Updaters.CovidReportsUpdater do
backup_dir = Path.join(dir, "backup/situation_report")
output_dir = Path.join(dir, "output/situation_report")

unless File.dir?(backup_dir) do
File.mkdir_p!(backup_dir)
File.mkdir_p!(backup_dir)
remove_consolidations(backup_dir)

if File.dir?(output_dir) do
Logger.info("Backing up data from previous update")
if File.dir?(output_dir) do
Logger.info("Backing up data from previous update")

copy_consolidations(output_dir, backup_dir)
else
with {:ok, data_path} <- Application.fetch_env(:health_board, :data_path) do
Logger.info("Backing up data from base data")
copy_consolidations(output_dir, backup_dir)
else
with {:ok, data_path} <- Application.fetch_env(:health_board, :data_path) do
Logger.info("Backing up data from base data")

data_path
|> Path.join("situation_report")
|> copy_consolidations(backup_dir)
end
data_path
|> Path.join("situation_report")
|> copy_consolidations(backup_dir)
end
end

Expand Down
Loading

0 comments on commit 323d121

Please sign in to comment.