sidekiq-queue-pause 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/sidekiq-queue-pause.rb +84 -0
  3. metadata +59 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8c930391c65c28ca0697a4b9dd5eeaad27ced197
4
+ data.tar.gz: eb5a3a8a3c11c452a58b1a7afea09c484ddf0ba9
5
+ SHA512:
6
+ metadata.gz: 70551e734828c25b9bc7d57230dcdd8c1ab089279fca2c1250ffc4afec377d6a9f660496b84f51c383999d28fdb9379df1b772c53876a1891a2dc6ba1650e843
7
+ data.tar.gz: 7b57627868a2830c47eabbbd9d10f17e08b0493a1e0d5e70fd4823fc62e1c5f3621895bcf2f7db5fe924d71d7adc2b25e44e57b1619611907ef287946532f3e2
@@ -0,0 +1,84 @@
1
+ require 'celluloid'
2
+ require 'sidekiq'
3
+ require 'sidekiq/fetch'
4
+
5
+ module Sidekiq
6
+ module QueuePause
7
+ PREFIX = 'queue_pause'
8
+
9
+ class << self
10
+ attr_accessor :retry_after
11
+ attr_writer :process_key
12
+
13
+ def process_key(&block)
14
+ if block_given?
15
+ @process_key = block
16
+ else
17
+ @process_key.is_a?(Proc) ? @process_key.call : @process_key
18
+ end
19
+ end
20
+
21
+ def pause(queue, pkey = nil)
22
+ Sidekiq.redis { |it| it.set rkey(queue, pkey), true }
23
+ end
24
+
25
+ def unpause(queue, pkey = nil)
26
+ Sidekiq.redis { |it| it.del rkey(queue, pkey) }
27
+ end
28
+
29
+ def paused?(queue, pkey = nil)
30
+ Sidekiq.redis { |it| it.exists rkey(queue, pkey) }
31
+ end
32
+
33
+ def unpause_all
34
+ Sidekiq.redis { |it| it.keys("#{PREFIX}:*").each { |k| it.del k } }
35
+ end
36
+
37
+ private
38
+
39
+ def rkey(queue, pkey)
40
+ pkey ? "#{PREFIX}:#{queue}:#{pkey}" : "#{PREFIX}:#{queue}"
41
+ end
42
+ end
43
+
44
+ class PausingFetch < Sidekiq::BasicFetch
45
+ def retrieve_work
46
+ qcmd = unpaused_queues_cmd
47
+
48
+ if qcmd.size > 1
49
+ retrieve_work_for_queues qcmd
50
+ else
51
+ sleep(Sidekiq::QueuePause.retry_after || Sidekiq::Fetcher::TIMEOUT)
52
+ nil
53
+ end
54
+ end
55
+
56
+ def retrieve_work_for_queues(qcmd)
57
+ work = Sidekiq.redis { |conn| conn.brpop(*qcmd) }
58
+ UnitOfWork.new(*work) if work
59
+ end
60
+
61
+ def unpaused_queues_cmd
62
+ queues = queues_cmd
63
+ queues.reject do |q|
64
+ q != Sidekiq::Fetcher::TIMEOUT &&
65
+ Sidekiq::QueuePause.paused?(q.gsub('queue:', ''), Sidekiq::QueuePause.process_key)
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ class Queue
72
+ def pause(pkey = nil)
73
+ Sidekiq::QueuePause.pause(name, pkey)
74
+ end
75
+
76
+ def unpause(pkey = nil)
77
+ Sidekiq::QueuePause.unpause(name, pkey)
78
+ end
79
+
80
+ def paused?(pkey = nil)
81
+ Sidekiq::QueuePause.paused?(name, pkey)
82
+ end
83
+ end
84
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq-queue-pause
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - FlavourSys Technology GmbH
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sidekiq
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ description: Let's you pause/unpause individual sidekiq queues.
28
+ email:
29
+ - technology@flavoursys.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/sidekiq-queue-pause.rb
35
+ homepage: http://github.com/FlavourSys/sidekiq-queue-pause
36
+ licenses:
37
+ - MIT
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.2.2
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Pause a Sidekiq queue
59
+ test_files: []