sidekiq-sqs 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/sidekiq-sqs.rb +2 -1
- data/lib/sidekiq-sqs/fetcher.rb +10 -0
- data/lib/sidekiq-sqs/manager.rb +46 -1
- data/lib/sidekiq-sqs/processor.rb +1 -1
- data/lib/sidekiq-sqs/version.rb +1 -1
- data/sidekiq-sqs.gemspec +1 -1
- metadata +3 -3
data/lib/sidekiq-sqs.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_support'
|
2
|
+
require 'aws-sdk'
|
2
3
|
|
3
4
|
require "sidekiq-sqs/version"
|
4
5
|
require 'sidekiq-sqs/manager'
|
@@ -27,7 +28,7 @@ module Sidekiq
|
|
27
28
|
|
28
29
|
# Can't figure how to include/extend and not get a private method...
|
29
30
|
def Sidekiq.sqs
|
30
|
-
|
31
|
+
AWS::SQS.new
|
31
32
|
end
|
32
33
|
|
33
34
|
Sidekiq.configure_server do |config|
|
data/lib/sidekiq-sqs/fetcher.rb
CHANGED
@@ -16,6 +16,16 @@ module Sidekiq
|
|
16
16
|
@unique_queues = @queues.uniq
|
17
17
|
end
|
18
18
|
|
19
|
+
# TODO Since there's only one fetcher per manager, we run into the issue
|
20
|
+
# where it takes longer to fetch a single job that it does to process,
|
21
|
+
# on average, so that we have waiting workers even if we have jobs in the
|
22
|
+
# queue because, with the HTTP round trip, fetching single messages is too
|
23
|
+
# slow.
|
24
|
+
#
|
25
|
+
# We could fetch 10 at a time, but then we have to worry about stuffing them
|
26
|
+
# into a "cache", and pushing them back into SQS if we die or exit. We could,
|
27
|
+
# I guess, just let the "hold" on them expire, and then they would be picked
|
28
|
+
# up again. I wonder if that would be 'good enough'
|
19
29
|
def fetch
|
20
30
|
watchdog('Fetcher#fetch died') do
|
21
31
|
return if Sidekiq::Fetcher.done?
|
data/lib/sidekiq-sqs/manager.rb
CHANGED
@@ -4,7 +4,14 @@ module Sidekiq
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
remove_method :assign
|
7
|
+
remove_method :assign, :dispatch, :stop
|
8
|
+
alias_method_chain :initialize, :sqs
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize_with_sqs(options = {})
|
12
|
+
initialize_without_sqs(options)
|
13
|
+
|
14
|
+
@fetcher = Sidekiq::Fetcher.pool(args: [current_actor, options[:queues], !!options[:strict]])
|
8
15
|
end
|
9
16
|
|
10
17
|
def assign(msg, queue)
|
@@ -24,6 +31,44 @@ module Sidekiq
|
|
24
31
|
end
|
25
32
|
end
|
26
33
|
end
|
34
|
+
|
35
|
+
def stop(options={})
|
36
|
+
watchdog('Manager#stop died') do
|
37
|
+
shutdown = options[:shutdown]
|
38
|
+
timeout = options[:timeout]
|
39
|
+
|
40
|
+
@done = true
|
41
|
+
Sidekiq::Fetcher.done!
|
42
|
+
@fetcher.finalize
|
43
|
+
|
44
|
+
logger.info { "Shutting down #{@ready.size} quiet workers" }
|
45
|
+
@ready.each { |x| x.terminate if x.alive? }
|
46
|
+
@ready.clear
|
47
|
+
|
48
|
+
logger.debug { "Clearing workers in redis" }
|
49
|
+
Sidekiq.redis do |conn|
|
50
|
+
workers = conn.smembers('workers')
|
51
|
+
workers.each do |name|
|
52
|
+
conn.srem('workers', name) if name =~ /:#{process_id}-/
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
return after(0) { signal(:shutdown) } if @busy.empty?
|
57
|
+
logger.info { "Pausing up to #{timeout} seconds to allow workers to finish..." }
|
58
|
+
hard_shutdown_in timeout if shutdown
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
def dispatch
|
64
|
+
return if stopped?
|
65
|
+
# This is a safety check to ensure we haven't leaked
|
66
|
+
# processors somehow.
|
67
|
+
raise "BUG: No processors, cannot continue!" if @ready.empty? && @busy.empty?
|
68
|
+
raise "No ready processor!?" if @ready.empty?
|
69
|
+
|
70
|
+
@fetcher.fetch!
|
71
|
+
end
|
27
72
|
end
|
28
73
|
end
|
29
74
|
end
|
@@ -14,7 +14,7 @@ module Sidekiq
|
|
14
14
|
begin
|
15
15
|
process_without_sqs(Zlib::Inflate.inflate(Base64.decode64(sqs_message.body)), queue)
|
16
16
|
ensure
|
17
|
-
# FIXME Maybe we want to requeue here?
|
17
|
+
# FIXME Maybe we want to requeue here, if there's a non-job related error?
|
18
18
|
sqs_message.delete
|
19
19
|
end
|
20
20
|
end
|
data/lib/sidekiq-sqs/version.rb
CHANGED
data/sidekiq-sqs.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.email = ["jon@burningbush.us"]
|
11
11
|
gem.description = %q{SQS backed job store for Sidekiq. Redis is still used for stats/job worker tracking}
|
12
12
|
gem.summary = %q{SQS backed job store for Sidekiq}
|
13
|
-
gem.homepage = ""
|
13
|
+
gem.homepage = "http://github.com/jmoses/sidekiq-sqs"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-sqs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -132,7 +132,7 @@ files:
|
|
132
132
|
- sidekiq-sqs.gemspec
|
133
133
|
- spec/sidekiq-sqs/middleware/compression_spec.rb
|
134
134
|
- spec/spec_helper.rb
|
135
|
-
homepage:
|
135
|
+
homepage: http://github.com/jmoses/sidekiq-sqs
|
136
136
|
licenses: []
|
137
137
|
post_install_message:
|
138
138
|
rdoc_options: []
|