Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Delete locks whenever jobs are removed via web UI. #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions lib/sidekiq-middleware/sidekiq_ext.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# encoding: utf-8

#
# The following classes extend their respective Sidekiq classes (in particular,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some tests for this would be great thing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integration tests, right?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think so.

# they extend the delete/clear methods). The extensions make sure that the
# locks are removed from Redis when the jobs are.
#
# Reference:
# https://github.com/mperham/sidekiq/blob/master/lib/sidekiq/api.rb
# https://github.com/mperham/sidekiq/blob/master/lib/sidekiq/web.rb
#

module Sidekiq
class Job
module UniqueExtension
def self.included(base)
base.class_eval do
alias_method :delete_orig, :delete
alias_method :delete, :delete_ext
end
end

def delete_ext
cklass = klass.constantize
cklass.unlock!(args.first) if cklass.respond_to? :lock
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this supports only workers with manual option. Can we make it work with regular ones as well?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, unlock! is not something that UniqueJobs provides. This is just an example.

delete_orig
end
end

include UniqueExtension
end

class Queue
module UniqueExtension
def self.included(base)
base.class_eval do
alias_method :clear_orig, :clear
alias_method :clear, :clear_ext
end
end

def clear_ext
self.each { |job| job.delete }
clear_orig
end
end

include UniqueExtension
end

class SortedSet
module UniqueExtension
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to work as same as it works for Queue. Can we just reuse this code?

def self.included(base)
base.class_eval do
alias_method :clear_orig, :clear
alias_method :clear, :clear_ext
end
end

def clear_ext
self.each { |job| job.delete }
clear_orig
end
end

include UniqueExtension
end
end