Skip to content

Instantly share code, notes, and snippets.

@wellsmuker
Forked from Chocksy/kill_sidekiq_job.rb
Created March 14, 2023 06:19
Show Gist options
  • Save wellsmuker/f2ffd47e20bac18bdb80d9b6faae95e3 to your computer and use it in GitHub Desktop.
Save wellsmuker/f2ffd47e20bac18bdb80d9b6faae95e3 to your computer and use it in GitHub Desktop.

Revisions

  1. @Chocksy Chocksy revised this gist Sep 22, 2022. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions kill_sidekiq_job.rb
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,20 @@
    # FOR BUSY JOBS
    # take the process_id from the /busy page in sidekiq and kill the longest running one.
    workers = Sidekiq::Workers.new
    long_process_id = 'integration.3:4:71111aaa111' # Eg: 'integration.3:4:71d1d7f4ef5a'
    workers.each do |process_id, thread_id, work|
    process = Sidekiq::Process.new('identity' => process_id)
    process.stop! if process_id == 'integration.3:4:71d1d7f4ef5a'
    process.stop! if process_id == long_process_id
    end

    # FOR SCHEDULED JOBS
    # you need to know the jid to make this happen
    job = Sidekiq::ScheduledSet.new.find_job('e460064eda529b97e93314d4')
    jid = 'scheduled111aaa222' # Eg: 'e460064eda529b97e93314d4'
    job = Sidekiq::ScheduledSet.new.find_job(jid)
    job.delete # will just remove the job

    # FOR RETRY JOBS
    # you need to know the jid to make this happen
    job = Sidekiq::RetrySet.new.find_job('e460064eda529b97e93314d4')
    jid = 'retry111aaa222aaa' # Eg: 'e460064eda529b97e93314d4'
    job = Sidekiq::RetrySet.new.find_job(jid)
    job.delete # will just remove the job
  2. @Chocksy Chocksy revised this gist Mar 27, 2019. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion kill_sidekiq_job.rb
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,17 @@
    # FOR BUSY JOBS
    # take the process_id from the /busy page in sidekiq and kill the longest running one.
    workers = Sidekiq::Workers.new
    workers.each do |process_id, thread_id, work|
    process = Sidekiq::Process.new('identity' => process_id)
    process.stop! if process_id == 'integration.3:4:71d1d7f4ef5a'
    end
    end

    # FOR SCHEDULED JOBS
    # you need to know the jid to make this happen
    job = Sidekiq::ScheduledSet.new.find_job('e460064eda529b97e93314d4')
    job.delete # will just remove the job

    # FOR RETRY JOBS
    # you need to know the jid to make this happen
    job = Sidekiq::RetrySet.new.find_job('e460064eda529b97e93314d4')
    job.delete # will just remove the job
  3. @Chocksy Chocksy created this gist Feb 1, 2018.
    6 changes: 6 additions & 0 deletions kill_sidekiq_job.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    # take the process_id from the /busy page in sidekiq and kill the longest running one.
    workers = Sidekiq::Workers.new
    workers.each do |process_id, thread_id, work|
    process = Sidekiq::Process.new('identity' => process_id)
    process.stop! if process_id == 'integration.3:4:71d1d7f4ef5a'
    end