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-12-01 22:07:01 +08:00
|
|
|
def forward(my_module)
|
2020-08-25 21:02:25 +08:00
|
|
|
my_module.assigned_repositories.each do |repository|
|
2024-02-06 21:23:01 +08:00
|
|
|
repository_snapshot = ::RepositorySnapshot.create_preliminary!(repository, my_module)
|
2020-09-11 22:08:03 +08:00
|
|
|
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!
|
2022-03-25 22:38:15 +08:00
|
|
|
raise MyModuleStatus::MyModuleStatusTransitionError.new(
|
|
|
|
{
|
|
|
|
type: :repository_snapshot,
|
|
|
|
repository_id: repository_snapshot.parent_id,
|
|
|
|
message: service.errors.values.join("\n")
|
|
|
|
}
|
|
|
|
)
|
2020-09-11 22:08:03 +08:00
|
|
|
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
|