mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-12 09:20:45 +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
|
queue_as :high_priority
|
||||||
|
|
||||||
def perform(my_module, my_module_status_consequences, status_changing_direction)
|
def perform(my_module, my_module_status_consequences, status_changing_direction)
|
||||||
error_raised = false
|
error = nil
|
||||||
my_module.transaction do
|
my_module.transaction(requires_new: true) do
|
||||||
my_module_status_consequences.each do |consequence|
|
my_module_status_consequences.each do |consequence|
|
||||||
consequence.public_send(status_changing_direction, my_module)
|
consequence.public_send(status_changing_direction, my_module)
|
||||||
end
|
end
|
||||||
my_module.update!(status_changing: false)
|
my_module.update!(status_changing: false)
|
||||||
|
my_module.update!(last_transition_error: nil)
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
Rails.logger.error(e.message)
|
Rails.logger.error(e.message)
|
||||||
Rails.logger.error(e.backtrace.join("\n"))
|
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
|
end
|
||||||
if error_raised
|
raise ActiveRecord::Rollback
|
||||||
|
end
|
||||||
|
if error.present?
|
||||||
my_module.my_module_status = my_module.changing_from_my_module_status
|
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.status_changing = false
|
||||||
my_module.save!
|
my_module.save!
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -478,16 +478,11 @@ class MyModule < ApplicationRecord
|
||||||
yield
|
yield
|
||||||
|
|
||||||
if my_module_status.my_module_status_consequences.any?(&:runs_in_background?)
|
if my_module_status.my_module_status_consequences.any?(&:runs_in_background?)
|
||||||
MyModuleStatusConsequencesJob.perform_later(
|
MyModuleStatusConsequencesJob
|
||||||
self,
|
.perform_later(self, my_module_status.my_module_status_consequences.to_a, status_changing_direction)
|
||||||
my_module_status.my_module_status_consequences.to_a,
|
|
||||||
status_changing_direction
|
|
||||||
)
|
|
||||||
else
|
else
|
||||||
my_module_status.my_module_status_consequences.each do |consequence|
|
MyModuleStatusConsequencesJob
|
||||||
consequence.public_send(status_changing_direction, self)
|
.perform_now(self, my_module_status.my_module_status_consequences.to_a, status_changing_direction)
|
||||||
end
|
|
||||||
update!(status_changing: false)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,15 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class MyModuleStatus < ApplicationRecord
|
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_modules, dependent: :nullify
|
||||||
has_many :my_module_status_conditions, dependent: :destroy
|
has_many :my_module_status_conditions, dependent: :destroy
|
||||||
has_many :my_module_status_consequences, dependent: :destroy
|
has_many :my_module_status_consequences, dependent: :destroy
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,13 @@ module MyModuleStatusConsequences
|
||||||
|
|
||||||
unless service.succeed?
|
unless service.succeed?
|
||||||
repository_snapshot.failed!
|
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
|
end
|
||||||
|
|
||||||
snapshot = service.repository_snapshot
|
snapshot = service.repository_snapshot
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue