Draft: Implement BulkDeleteRunnersByFilterWorker
What does this MR do and why?
Describe in detail what your merge request does and why.
This MR implements a worker to help with deleting runners in bulk by specifying a filter which gets passed to Ci::RunnersFinder
. This will be used in !91471 (closed) to expose this functionality in a GraphQL mutation.
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.
-
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!)
-
Kick off
BulkDeleteRunnersService
, which will use Sidekiq to schedule the worker and give you back a job ID:pry(main)> ::Ci::Runners::BulkDeleteRunnersService.new(User.find(1), filter: { 'active' => false } ).execute => {:job_id=>"d4fbffb8d1564f106fce0348"}
-
Check
log/sidekiq.log
withtail log/sidekiq.log | grep BulkDeleteRunnersByFilterWorker
:9 {"severity":"INFO","time":"2022-07-27T09:46:19.043Z","retry":3,"queue":"default","backtrace":true,"version":0,"args":["1","{\"active\"=\u003efalse}"],"class":"Ci::Runners::BulkDeleteRunnersByFilterWorker","jid":"78cfa1b110bd17c9f1373c9a","created_at":"2022-07-27T09:46:18.905Z","meta.feature_category":"runner_fleet","correlation_id":"6749adcbcac76b289f091500b74c7056","worker_data_consistency":"always","idempotency_key":"resque:gitlab:duplicate:default:ac49e54d8b327a517d13be23987c9f34243fd643b10cbd69525d62572f9b9803","size_limiter":"validated","enqueued_at":"2022-07-27T09:46:18.935Z","job_size_bytes":39,"pid":70319,"message":"Ci::Runners::BulkDeleteRunnersByFilterWorker JID-78cfa1b110bd17c9f1373c9a: start","job_status":"start","scheduling_latency_s":0.108728}
-
Confirm that the previous runner is no longer there:
pry(main)> runner.reload ActiveRecord::RecordNotFound: Couldn't find Ci::Runner with 'id'=1214
-
Create some more runners. This time we'll delete them by id:
pry(main)> runner = Ci::Runner.new(runner_type: :instance_type, active: false).tap(&:save!)
-
Kick off
BulkDeleteRunnersService
synchronously:pry(main)> ::Ci::Runners::BulkDeleteRunnersService.new(User.find(1), runners: [runner] ).execute => {:count=>1}
-
Confirm that the previous runner is no longer there:
pry(main)> runner.reload ActiveRecord::RecordNotFound: Couldn't find Ci::Runner with 'id'=1215
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.