[SCI-5260] Add afterward and backward actions to consequence

This commit is contained in:
aignatov-bio 2020-12-01 15:07:01 +01:00
parent ad960d801d
commit 04624692d3
6 changed files with 11 additions and 13 deletions

View file

@ -7,7 +7,7 @@ class MyModuleStatusConsequencesJob < ApplicationJob
error_raised = false
my_module.transaction do
my_module_status_consequences.each do |consequence|
consequence.call(my_module) if consequence.public_send("#{status_changing_direction}_execution")
consequence.public_send(status_changing_direction, my_module)
end
my_module.update!(status_changing: false)
rescue StandardError => e

View file

@ -518,7 +518,7 @@ class MyModule < ApplicationRecord
)
else
my_module_status.my_module_status_consequences.each do |consequence|
consequence.call(self) if consequence.public_send("#{status_changing_direction}_execution")
consequence.public_send(status_changing_direction, self)
end
update!(status_changing: false)
end

View file

@ -3,15 +3,13 @@
class MyModuleStatusConsequence < ApplicationRecord
belongs_to :my_module_status
def forward(my_module)
end
def backward(my_module)
end
def runs_in_background?
false
end
def forward_execution
true
end
def backward_execution
true
end
end

View file

@ -3,7 +3,7 @@
# Just an example, to be replaced with an actual implementation
module MyModuleStatusConsequences
class Completion < MyModuleStatusConsequence
def call(my_module)
def forward(my_module)
my_module.state = 'completed'
my_module.completed_on = DateTime.now
my_module.save!

View file

@ -6,7 +6,7 @@ module MyModuleStatusConsequences
true
end
def call(my_module)
def forward(my_module)
my_module.assigned_repositories.each do |repository|
repository_snapshot = ::RepositorySnapshot.create_preliminary(repository, my_module)
service = Repositories::SnapshotProvisioningService.call(repository_snapshot: repository_snapshot)

View file

@ -3,7 +3,7 @@
# Just an example, to be replaced with an actual implementation
module MyModuleStatusConsequences
class Uncompletion < MyModuleStatusConsequence
def call(my_module)
def backward(my_module)
return unless my_module.state == 'completed'
my_module.state = 'uncompleted'