2020-09-11 22:08:03 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class MyModuleStatusConsequencesJob < ApplicationJob
|
|
|
|
queue_as :high_priority
|
|
|
|
|
2020-11-30 19:28:29 +08:00
|
|
|
def perform(my_module, my_module_status_consequences, status_changing_direction)
|
2020-09-11 22:08:03 +08:00
|
|
|
error_raised = false
|
|
|
|
my_module.transaction do
|
|
|
|
my_module_status_consequences.each do |consequence|
|
2020-12-01 22:07:01 +08:00
|
|
|
consequence.public_send(status_changing_direction, my_module)
|
2020-09-11 22:08:03 +08:00
|
|
|
end
|
|
|
|
my_module.update!(status_changing: false)
|
|
|
|
rescue StandardError => e
|
|
|
|
Rails.logger.error(e.message)
|
|
|
|
Rails.logger.error(e.backtrace.join("\n"))
|
|
|
|
error_raised = true
|
|
|
|
end
|
|
|
|
if error_raised
|
|
|
|
my_module.my_module_status = my_module.changing_from_my_module_status
|
|
|
|
my_module.status_changing = false
|
|
|
|
my_module.save!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|