From 04624692d3635d1658bae306c44c663d351cd2a0 Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Tue, 1 Dec 2020 15:07:01 +0100 Subject: [PATCH] [SCI-5260] Add afterward and backward actions to consequence --- app/jobs/my_module_status_consequences_job.rb | 2 +- app/models/my_module.rb | 2 +- app/models/my_module_status_consequence.rb | 14 ++++++-------- .../my_module_status_consequences/completion.rb | 2 +- .../repository_snapshot.rb | 2 +- .../my_module_status_consequences/uncompletion.rb | 2 +- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/app/jobs/my_module_status_consequences_job.rb b/app/jobs/my_module_status_consequences_job.rb index 5ed582c3a..a27c547e9 100644 --- a/app/jobs/my_module_status_consequences_job.rb +++ b/app/jobs/my_module_status_consequences_job.rb @@ -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 diff --git a/app/models/my_module.rb b/app/models/my_module.rb index 780ea7fed..6d98568b0 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -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 diff --git a/app/models/my_module_status_consequence.rb b/app/models/my_module_status_consequence.rb index 6e8fbf5e1..3b14b0fa1 100644 --- a/app/models/my_module_status_consequence.rb +++ b/app/models/my_module_status_consequence.rb @@ -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 diff --git a/app/models/my_module_status_consequences/completion.rb b/app/models/my_module_status_consequences/completion.rb index 4111f045c..2f1676cc6 100644 --- a/app/models/my_module_status_consequences/completion.rb +++ b/app/models/my_module_status_consequences/completion.rb @@ -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! diff --git a/app/models/my_module_status_consequences/repository_snapshot.rb b/app/models/my_module_status_consequences/repository_snapshot.rb index bd8d8baf9..4760d9102 100644 --- a/app/models/my_module_status_consequences/repository_snapshot.rb +++ b/app/models/my_module_status_consequences/repository_snapshot.rb @@ -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) diff --git a/app/models/my_module_status_consequences/uncompletion.rb b/app/models/my_module_status_consequences/uncompletion.rb index 4d3a5e184..cfbb19ccf 100644 --- a/app/models/my_module_status_consequences/uncompletion.rb +++ b/app/models/my_module_status_consequences/uncompletion.rb @@ -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'