mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-24 08:43:13 +08:00
Improve error reporting in task status transition [SCI-6611] (#3952)
This commit is contained in:
parent
305df378ec
commit
5d111d3350
4 changed files with 31 additions and 14 deletions
|
@ -4,19 +4,26 @@ class MyModuleStatusConsequencesJob < ApplicationJob
|
|||
queue_as :high_priority
|
||||
|
||||
def perform(my_module, my_module_status_consequences, status_changing_direction)
|
||||
error_raised = false
|
||||
my_module.transaction do
|
||||
error = nil
|
||||
my_module.transaction(requires_new: true) do
|
||||
my_module_status_consequences.each do |consequence|
|
||||
consequence.public_send(status_changing_direction, my_module)
|
||||
end
|
||||
my_module.update!(status_changing: false)
|
||||
my_module.update!(last_transition_error: nil)
|
||||
rescue StandardError => e
|
||||
Rails.logger.error(e.message)
|
||||
Rails.logger.error(e.backtrace.join("\n"))
|
||||
error_raised = true
|
||||
error = if e.is_a?(MyModuleStatus::MyModuleStatusTransitionError)
|
||||
e.error
|
||||
else
|
||||
{ type: :general, message: e.message }
|
||||
end
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
if error_raised
|
||||
if error.present?
|
||||
my_module.my_module_status = my_module.changing_from_my_module_status
|
||||
my_module.last_transition_error = error
|
||||
my_module.status_changing = false
|
||||
my_module.save!
|
||||
end
|
||||
|
|
|
@ -478,16 +478,11 @@ class MyModule < ApplicationRecord
|
|||
yield
|
||||
|
||||
if my_module_status.my_module_status_consequences.any?(&:runs_in_background?)
|
||||
MyModuleStatusConsequencesJob.perform_later(
|
||||
self,
|
||||
my_module_status.my_module_status_consequences.to_a,
|
||||
status_changing_direction
|
||||
)
|
||||
MyModuleStatusConsequencesJob
|
||||
.perform_later(self, my_module_status.my_module_status_consequences.to_a, status_changing_direction)
|
||||
else
|
||||
my_module_status.my_module_status_consequences.each do |consequence|
|
||||
consequence.public_send(status_changing_direction, self)
|
||||
end
|
||||
update!(status_changing: false)
|
||||
MyModuleStatusConsequencesJob
|
||||
.perform_now(self, my_module_status.my_module_status_consequences.to_a, status_changing_direction)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class MyModuleStatus < ApplicationRecord
|
||||
class MyModuleStatusTransitionError < StandardError
|
||||
attr_reader :error
|
||||
|
||||
def initialize(error)
|
||||
@error = error
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
has_many :my_modules, dependent: :nullify
|
||||
has_many :my_module_status_conditions, dependent: :destroy
|
||||
has_many :my_module_status_consequences, dependent: :destroy
|
||||
|
|
|
@ -13,7 +13,13 @@ module MyModuleStatusConsequences
|
|||
|
||||
unless service.succeed?
|
||||
repository_snapshot.failed!
|
||||
raise StandardError, service.errors
|
||||
raise MyModuleStatus::MyModuleStatusTransitionError.new(
|
||||
{
|
||||
type: :repository_snapshot,
|
||||
repository_id: repository_snapshot.parent_id,
|
||||
message: service.errors.values.join("\n")
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
snapshot = service.repository_snapshot
|
||||
|
|
Loading…
Reference in a new issue