Files
ubicloud/prog/github/destroy_github_installation.rb
Enes Cakir 1204783972 Pop from DestroyGithubInstallation if installation already destroyed
We assemble the DestroyGithubInstallation prog in several places. For
instance, if the same webhook is delivered twice, we end up with
multiple instances for the same installation.

When the first instance destroys the installation, the second one starts
to fail.

We could add a check to ensure only a single instance is running, but
the current implementation is more robust and straightforward.

We already have a similar check in place within the
Prog::Vnet::CertServer prog.
2024-11-12 12:17:50 +00:00

52 lines
1.2 KiB
Ruby

# frozen_string_literal: true
require_relative "../../lib/util"
class Prog::Github::DestroyGithubInstallation < Prog::Base
subject_is :github_installation
def self.assemble(installation)
Strand.create_with_id(
prog: "Github::DestroyGithubInstallation",
label: "start",
stack: [{"subject_id" => installation.id}]
)
end
label def before_run
pop "github installation is destroyed" unless github_installation
end
label def start
register_deadline(nil, 10 * 60)
hop_delete_installation
end
label def delete_installation
begin
Github.app_client.delete_installation(github_installation.installation_id)
rescue Octokit::NotFound
end
hop_destroy_resources
end
label def destroy_resources
github_installation.repositories.map(&:incr_destroy)
github_installation.runners.map do |runner|
runner.incr_skip_deregistration
runner.incr_destroy
end
hop_destroy
end
label def destroy
nap 10 unless github_installation.runners_dataset.empty?
nap 10 unless github_installation.repositories_dataset.empty?
github_installation.destroy
Clog.emit("GithubInstallation is deleted.") { github_installation }
pop "github installation destroyed"
end
end