Add sidekiq_remove_jobs migration for TrendingProjectsWorker

See #553408 (closed) for context

Step 2 of removing TrendingProjectsWorker. Adds a migration that clears any remaining enqueued instances from Sidekiq and removes the cron job entry from the scheduled worker set.

Reference: https://docs.gitlab.com/development/sidekiq/compatibility_across_updates/#removing-worker-classes

Prerequisite: #555342 (closed) must be merged and deployed.

Implementation Steps

  1. Generate a regular (non-post-deployment) migration:

    rails g migration RemoveTrendingProjectsWorkerJobInstances
  2. Implement the migration:

    class RemoveTrendingProjectsWorkerJobInstances < Gitlab::Database::Migration[2.1]
      disable_ddl_transaction!
    
      DEPRECATED_JOB_CLASSES = %w[TrendingProjectsWorker]
    
      def up
        Gitlab::SidekiqSharding::Validator.allow_unrouted_sidekiq_calls do
          job_to_remove = Sidekiq::Cron::Job.find('trending_projects_worker')
          job_to_remove.destroy if job_to_remove
        end
    
        sidekiq_remove_jobs(job_klasses: DEPRECATED_JOB_CLASSES)
      end
    
      def down
        # This migration removes enqueued job instances and cannot be undone.
      end
    end
Edited by 🤖 GitLab Bot 🤖