scinote-web/app/models/my_module_status_consequences/repository_snapshot.rb

27 lines
830 B
Ruby
Raw Normal View History

# frozen_string_literal: true
module MyModuleStatusConsequences
class RepositorySnapshot < MyModuleStatusConsequence
def runs_in_background?
true
end
def forward(my_module)
2020-08-25 21:02:25 +08:00
my_module.assigned_repositories.each do |repository|
repository_snapshot = ::RepositorySnapshot.create_preliminary(repository, my_module)
service = Repositories::SnapshotProvisioningService.call(repository_snapshot: repository_snapshot)
unless service.succeed?
repository_snapshot.failed!
raise StandardError, service.errors
end
snapshot = service.repository_snapshot
unless snapshot.my_module.repository_snapshots.where(parent_id: snapshot.parent_id).find_by(selected: true)
snapshot.update!(selected: true)
end
end
end
end
end