Class: RequoteWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job, Workers::StatusBroadcastable
Defined in:
app/workers/requote_worker.rb

Overview

Sidekiq worker: requote.

Instance Attribute Summary

Attributes included from Workers::StatusBroadcastable

#broadcast_status_updates

Instance Method Summary collapse

Methods included from Workers::StatusBroadcastable::Overrides

#at, #store, #total

Instance Method Details

#perform(options = {}) ⇒ Object



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
37
38
39
40
41
42
# File 'app/workers/requote_worker.rb', line 10

def perform(options = {})
  quote_id = options[:quote_id]
  rma_id = options[:rma_id]
  redirect_path = options[:redirect_path] || "/quotes/#{quote_id}"

  total 3
  at(1, 'Loading quote...')

  quote = Quote.find(quote_id)

  at(2, 'Creating revised quote...')

  reviser = Quote::Reviser.new(quote, rma_id: rma_id)
  new_quote = reviser.revise
  errors = reviser.errors

  at(3, 'Finalizing...')

  if errors.empty?
    store redirect_to: "/quotes/#{new_quote.id}/rooms"
    store message: 'Quote revised successfully.'
  else
    store redirect_to: redirect_path
    store message: "Could not requote: #{errors.join(', ')}"
    store error_message: "Could not requote: #{errors.join(', ')}"
  end
rescue StandardError => e
  store message: "Error requoting: #{e.message}"
  store error_message: "Failed to requote: #{e.message}"
  store redirect_to: redirect_path
  Rails.logger.error("RequoteWorker error for quote #{quote_id}: #{e.message}\n#{e.backtrace.join("\n")}")
  raise # AppSignal catches this automatically
end