Class: Disqualified::Main

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/disqualified/main.rb

Constant Summary

Constants included from Logging

Logging::ERROR_CONTEXT_TYPE, Logging::ERROR_HOOK_TYPE

Instance Method Summary collapse

Methods included from Logging

format_log, handle_error

Constructor Details

#initialize(error_hooks:, logger:) ⇒ Main

Returns a new instance of Main.



4
5
6
7
# File 'lib/disqualified/main.rb', line 4

def initialize(error_hooks:, logger:)
  @error_hooks = error_hooks
  @logger = logger
end

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/disqualified/main.rb', line 9

def call
  Rails.application.reloader.wrap do
    record = Disqualified::Record.claim_one!
    run_id = record.locked_by
    record.send(:instantiate_handler_and_perform_with_args)
    record.finish
    @logger.info do
      format_log("Disqualified::Main#call", "Runner #{run_id}", "Done")
    end
  rescue Disqualified::Error::NoClaimableJob
    @logger.warn do
      format_log("Disqualified::Main#call", "No claimable jobs")
    end
  rescue => e
    handle_error(@error_hooks, e, {record: record.attributes})
    @logger.error { format_log("Disqualified::Main#run", "Runner #{run_id}", "Rescued Record ##{record.id}") }
    record.requeue
  end
end