Class: AtlasEngine::CountryImportsController

Inherits:
ApplicationController show all
Extended by:
T::Sig
Includes:
LogHelper
Defined in:
app/controllers/atlas_engine/country_imports_controller.rb

Instance Method Summary collapse

Methods included from LogHelper

#log_error, #log_info, #log_warn

Constructor Details

#initializeCountryImportsController

Returns a new instance of CountryImportsController.



15
16
17
18
19
20
21
# File 'app/controllers/atlas_engine/country_imports_controller.rb', line 15

def initialize
  super
  @page = T.let(0, Integer)
  @country_import = T.let(T.unsafe(nil), T.nilable(CountryImport), checked: false)
  @country_imports = T.let(T.unsafe(nil), ActiveRecord::Relation, checked: false)
  @events = T.let(T.unsafe(nil), ActiveRecord::Relation, checked: false)
end

Instance Method Details

#indexObject



25
26
27
28
29
# File 'app/controllers/atlas_engine/country_imports_controller.rb', line 25

def index
  @country_imports = CountryImport.order(id: :desc)
    .offset(CountryImport::PAGE_SIZE * @page)
    .limit(CountryImport::PAGE_SIZE)
end

#interruptObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/atlas_engine/country_imports_controller.rb', line 38

def interrupt
  T.must(@country_import).interrupt!

  log_info("Country import manually interrupted", { country_import_id: T.must(@country_import).id })
  redirect_back_or_to(
    country_imports_url,
    notice: "Country import manually interrupted. Wait a few minutes for ongoing jobs to stop.",
  )
rescue => e
  log_error(
    "Country import manual interruption failed with #{e.class} - #{e.message}; stack trace #{e.backtrace.inspect}",
    { country_import_id: T.must(@country_import).id },
  )
  redirect_back_or_to(
    country_imports_url,
    alert: "Interruption of country import failed with #{e.class}, #{e.message}",
  )
end

#showObject



32
33
34
# File 'app/controllers/atlas_engine/country_imports_controller.rb', line 32

def show
  @events = Event.where(country_import: @country_import).order(id: :desc).limit(1000)
end