Skip to content

Create service to delete runners in bulk

What does this MR do and why?

Describe in detail what your merge request does and why.

This MR implements a service to help with deleting runners in bulk, by specifying runners as a relation or an array of IDs. Some background about this MR:

  • it will be used in a follow-up MR to expose this functionality in a GraphQL mutation;
  • the GraphQL mutation will be used in a new UX feature to allow admins to select multiple runners and to have them deleted by pressing a button;
  • I'm limiting the number of runners that can be deleted in bulk to 50, since we need to call destroy_all to execute hooks on runners (which do some cascading deletes on taggings/tags, `ci_runner_projects, and clear the runner queues). Not sure if this will require a database review, as this is already that can already be done by users (although individually).

Part of Select individual runners to delete from the ad... (#339525 - closed)

Screenshots or screen recordings

These are strongly recommended to assist reviewers and reduce the time to merge your change.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Ensure you have some runners registered using the following quick hack on the GDK Rails console:

    pry(main)> runner = Ci::Runner.new(runner_type: :instance_type, active: false).tap(&:save!)
  2. Kick off BulkDeleteRunnersService, which will use Sidekiq to schedule the worker and give you back a job ID:

    pry(main)> ::Ci::Runners::BulkDeleteRunnersService.new(runners: [runner.id] ).execute
    => {:deleted_count=>1, :deleted_ids => [1214]}
  3. Confirm that the previous runner is no longer there:

    pry(main)> runner.reload
    ActiveRecord::RecordNotFound: Couldn't find Ci::Runner with 'id'=1214

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Merge request reports