Class: Hackler::JobController

Inherits:
ApplicationController show all
Defined in:
app/controllers/hackler/job_controller.rb

Constant Summary collapse

REQUIRED_PARAMS =
%i[id base_url].freeze

Instance Method Summary collapse

Instance Method Details

#enqueueObject



11
12
13
14
15
16
17
18
19
# File 'app/controllers/hackler/job_controller.rb', line 11

def enqueue
  set_options = {}
  set_options[:wait_until] = Time.zone.at(@params[:timestamp]) if @params[:timestamp]

  Hackler::HacklerJob
    .set(**set_options)
    .perform_later(@params[:id], @params[:base_url])
  render head: :no_content
end

#workObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/hackler/job_controller.rb', line 21

def work
  job = Hackler::Job.find(@params[:id])
  ActiveJob::Base.execute(JSON.parse(job.data))
  job.destroy!
  render head: :no_content
rescue Exception => e # rubocop:disable Lint/RescueException
  # this needs to be a Exception, otherwise we won't catch e.g. `NoMethodError`s
  render json: {
    exception: {
      class:     e.class.name,
      message:   e.message,
      backtrace: Hackler.backtrace_cleaner.call(e.backtrace),
    },
  }, status: :internal_server_error
end