mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-25 01:04:02 +08:00
[SCI-5260] Add direction condition for status consequences
This commit is contained in:
parent
61baf88ab6
commit
0620da99de
3 changed files with 22 additions and 4 deletions
|
@ -3,11 +3,11 @@
|
|||
class MyModuleStatusConsequencesJob < ApplicationJob
|
||||
queue_as :high_priority
|
||||
|
||||
def perform(my_module, my_module_status_consequences)
|
||||
def perform(my_module, my_module_status_consequences, status_changing_direction)
|
||||
error_raised = false
|
||||
my_module.transaction do
|
||||
my_module_status_consequences.each do |consequence|
|
||||
consequence.call(my_module)
|
||||
consequence.call(my_module) if consequence.public_send("#{status_changing_direction}_execution")
|
||||
end
|
||||
my_module.update!(status_changing: false)
|
||||
rescue StandardError => e
|
||||
|
|
|
@ -506,13 +506,23 @@ class MyModule < ApplicationRecord
|
|||
self.changing_from_my_module_status_id = my_module_status_id_was if my_module_status_id_was.present?
|
||||
self.status_changing = true
|
||||
|
||||
status_changing_direction = if my_module_status.next_status&.id == my_module_status_id_was
|
||||
:backward
|
||||
else
|
||||
:forward
|
||||
end
|
||||
|
||||
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)
|
||||
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.call(self)
|
||||
consequence.call(self) if consequence.public_send("#{status_changing_direction}_execution")
|
||||
end
|
||||
update!(status_changing: false)
|
||||
end
|
||||
|
|
|
@ -6,4 +6,12 @@ class MyModuleStatusConsequence < ApplicationRecord
|
|||
def runs_in_background?
|
||||
false
|
||||
end
|
||||
|
||||
def forward_execution
|
||||
true
|
||||
end
|
||||
|
||||
def backward_execution
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue