mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-09 00:49:07 +08:00
Merge pull request #2847 from okriuchykhin/ok_SCI_5004_v2
Fix status consequences execution order [SCI-5004]
This commit is contained in:
commit
aadc0bebff
1 changed files with 7 additions and 2 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class MyModule < ApplicationRecord
|
class MyModule < ApplicationRecord
|
||||||
include ArchivableModel
|
include ArchivableModel
|
||||||
include SearchableModel
|
include SearchableModel
|
||||||
|
@ -9,7 +11,7 @@ class MyModule < ApplicationRecord
|
||||||
before_create :create_blank_protocol
|
before_create :create_blank_protocol
|
||||||
before_create :assign_default_status_flow
|
before_create :assign_default_status_flow
|
||||||
|
|
||||||
before_save :exec_status_consequences, if: :my_module_status_id_changed?
|
around_save :exec_status_consequences, if: :my_module_status_id_changed?
|
||||||
|
|
||||||
auto_strip_attributes :name, :description, nullify: false
|
auto_strip_attributes :name, :description, nullify: false
|
||||||
validates :name,
|
validates :name,
|
||||||
|
@ -538,14 +540,17 @@ class MyModule < ApplicationRecord
|
||||||
return if my_module_status.blank? || status_changing
|
return if my_module_status.blank? || status_changing
|
||||||
|
|
||||||
self.changing_from_my_module_status_id = my_module_status_id_was if my_module_status_id_was.present?
|
self.changing_from_my_module_status_id = my_module_status_id_was if my_module_status_id_was.present?
|
||||||
|
self.status_changing = true
|
||||||
|
|
||||||
|
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?)
|
||||||
self.status_changing = true
|
|
||||||
MyModuleStatusConsequencesJob.perform_later(self, my_module_status.my_module_status_consequences.to_a)
|
MyModuleStatusConsequencesJob.perform_later(self, my_module_status.my_module_status_consequences.to_a)
|
||||||
else
|
else
|
||||||
my_module_status.my_module_status_consequences.each do |consequence|
|
my_module_status.my_module_status_consequences.each do |consequence|
|
||||||
consequence.call(self)
|
consequence.call(self)
|
||||||
end
|
end
|
||||||
|
update!(status_changing: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue