2020-08-13 18:51:33 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module MyModuleStatusConsequences
|
|
|
|
class RepositorySnapshot < MyModuleStatusConsequence
|
2020-09-11 22:08:03 +08:00
|
|
|
def runs_in_background?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2020-08-13 18:51:33 +08:00
|
|
|
def call(my_module)
|
2020-08-25 21:02:25 +08:00
|
|
|
my_module.assigned_repositories.each do |repository|
|
2020-09-11 22:08:03 +08:00
|
|
|
repository_snapshot = ::RepositorySnapshot.create_preliminary(repository, my_module)
|
|
|
|
service = Repositories::SnapshotProvisioningService.call(repository_snapshot: repository_snapshot)
|
2020-10-15 21:21:44 +08:00
|
|
|
|
2020-09-11 22:08:03 +08:00
|
|
|
unless service.succeed?
|
|
|
|
repository_snapshot.failed!
|
|
|
|
raise StandardError, service.errors
|
|
|
|
end
|
2020-10-15 21:21:44 +08:00
|
|
|
|
|
|
|
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
|
2020-08-13 18:51:33 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|