-
-
Notifications
You must be signed in to change notification settings - Fork 279
/
server.rb
62 lines (55 loc) · 1.34 KB
/
server.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# frozen_string_literal: true
module SidekiqUniqueJobs
# The unique sidekiq middleware for the server processor
#
# @author Mikael Henriksson <[email protected]>
class Server
#
# @return [Proc] returns a default death handler for the gem to cleanup dead locks
DEATH_HANDLER = (lambda do |job, _ex|
return unless (digest = job["lock_digest"])
SidekiqUniqueJobs::Digests.new.delete_by_digest(digest)
end).freeze
#
# Configure the server middleware
#
#
# @return [Sidekiq] the sidekiq configuration
#
def self.configure(config)
config.on(:startup) { start }
config.on(:shutdown) { stop }
return unless config.respond_to?(:death_handlers)
config.death_handlers << death_handler
end
#
# Start the sidekiq unique jobs server process
#
#
# @return [void]
#
def self.start
SidekiqUniqueJobs::UpdateVersion.call
SidekiqUniqueJobs::Orphans::Manager.start
SidekiqUniqueJobs::Orphans::ReaperResurrector.start
end
#
# Stop the sidekiq unique jobs server process
#
#
# @return [void]
#
def self.stop
SidekiqUniqueJobs::Orphans::Manager.stop
end
#
# A death handler for dead jobs
#
#
# @return [lambda]
#
def self.death_handler
DEATH_HANDLER
end
end
end