kicks 3.1.1 → 3.2.0
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.
- checksums.yaml +4 -4
- data/ChangeLog.md +20 -3
- data/README.md +2 -1
- data/lib/active_job/queue_adapters/sneakers_adapter.rb +28 -30
- data/lib/sneakers/configuration.rb +1 -1
- data/lib/sneakers/handlers/maxretry.rb +6 -2
- data/lib/sneakers/publisher.rb +9 -5
- data/lib/sneakers/queue.rb +6 -2
- data/lib/sneakers/version.rb +1 -1
- data/spec/sneakers/publisher_spec.rb +26 -1
- data/spec/sneakers/queue_spec.rb +14 -9
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7899bb171d5e5399547c0b02c33753e23bc8cfaec63e614baa84cd473448a45d
|
4
|
+
data.tar.gz: 3b5b708557aae6c815a2ad23cf86115e5d39ad397cd1e52099ed2e621b26848a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57565fbb9e74e4b990f62e482293ff41cdffebb0b75875b4c654a34e4bb6ed037e2cc9305f15c1c6920e789749a484403badbc2f7aad58b811d614b0d2e51080
|
7
|
+
data.tar.gz: e6516ab5c10e167a1e94b0a80f82b68dbe330be53603d4cc7132104e0827f013c3cc930b1f3fe2ecc5f2f65a6cbf140707ccd3bd709fbae5ae0eae0747e2b8d7
|
data/ChangeLog.md
CHANGED
@@ -1,12 +1,29 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## Changes Between 3.
|
3
|
+
## Changes Between 3.2.0 and 3.3.0 (in development)
|
4
|
+
|
5
|
+
No (documented) changes yet.
|
6
|
+
|
7
|
+
|
8
|
+
## Changes Between 3.1.0 and 3.2.0 (Jan 26, 2025)
|
9
|
+
|
10
|
+
### Improved Support for Bring-Your-Own-Connection (BYOC)
|
11
|
+
|
12
|
+
Kicks now supports a callable (e.g. a proc) to be passed for an externally-initialized
|
13
|
+
and managed Bunny connection. In this case, it is entirely up to the caller
|
14
|
+
to configure the connection and call `Bunny::Session#start` on it
|
15
|
+
at the right moment.
|
16
|
+
|
17
|
+
Contributed by @tie.
|
18
|
+
|
19
|
+
GitHub issue: [#29](https://github.com/ruby-amqp/kicks/pull/29)
|
20
|
+
|
4
21
|
|
5
22
|
### ActiveJob Adapter Compatibility with Ruby on Rails Older Than 7.2
|
6
23
|
|
7
24
|
Contributed by @dixpac.
|
8
25
|
|
9
|
-
GitHub
|
26
|
+
GitHub issues: [#19](https://github.com/ruby-amqp/kicks/pull/19), [#28](https://github.com/ruby-amqp/kicks/pull/28)
|
10
27
|
|
11
28
|
|
12
29
|
## Changes Between 3.0.0 and 3.1.0 (Oct 20, 2024)
|
@@ -15,7 +32,7 @@ GitHub issue: [#19](https://github.com/ruby-amqp/kicks/pull/19)
|
|
15
32
|
|
16
33
|
Kicks now ships with an ActiveJob adapter for Ruby on Rails.
|
17
34
|
|
18
|
-
Contributed by
|
35
|
+
Contributed by dixpac.
|
19
36
|
|
20
37
|
GitHub issue: [#12](https://github.com/ruby-amqp/kicks/pull/12)
|
21
38
|
|
data/README.md
CHANGED
@@ -212,5 +212,6 @@ See [LICENSE](LICENSE.txt) for further details.
|
|
212
212
|
|
213
213
|
## Copyright
|
214
214
|
|
215
|
-
Copyright (c) 2023-2024 Kicks contributors
|
215
|
+
Copyright (c) 2023-2024 Kicks contributors.
|
216
|
+
|
216
217
|
Copyright (c) 2015-2023 [Dotan Nahum](http://gplus.to/dotan) [@jondot](http://twitter.com/jondot).
|
@@ -1,39 +1,37 @@
|
|
1
|
-
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
remove_const(:SneakersAdapter) if defined?("::#{name}::SneakersAdapter")
|
1
|
+
module ActiveJob
|
2
|
+
module QueueAdapters
|
3
|
+
# Explicitly remove the implementation existing in older Rails versions'.
|
4
|
+
remove_const(:SneakersAdapter) if const_defined?(:SneakersAdapter)
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
# = Sneakers adapter for Active Job
|
7
|
+
#
|
8
|
+
# To use Sneakers set the queue_adapter config to +:sneakers+.
|
9
|
+
#
|
10
|
+
# Rails.application.config.active_job.queue_adapter = :sneakers
|
11
|
+
class SneakersAdapter
|
12
|
+
def initialize
|
13
|
+
@monitor = Monitor.new
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
16
|
+
def enqueue(job)
|
17
|
+
@monitor.synchronize do
|
18
|
+
JobWrapper.from_queue job.queue_name
|
19
|
+
JobWrapper.enqueue ActiveSupport::JSON.encode(job.serialize)
|
22
20
|
end
|
21
|
+
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
def enqueue_at(job, timestamp)
|
24
|
+
raise NotImplementedError, 'This queueing backend does not support scheduling jobs.'
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
class JobWrapper
|
28
|
+
include Sneakers::Worker
|
29
|
+
from_queue 'default'
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
31
|
+
def work(msg)
|
32
|
+
job_data = ActiveSupport::JSON.decode(msg)
|
33
|
+
Base.execute job_data
|
34
|
+
ack!
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
@@ -5,7 +5,7 @@ module Sneakers
|
|
5
5
|
class Configuration
|
6
6
|
|
7
7
|
extend Forwardable
|
8
|
-
def_delegators :@hash, :to_hash, :[], :[]=, :==, :fetch, :delete, :has_key
|
8
|
+
def_delegators :@hash, :to_hash, :[], :[]=, :==, :fetch, :delete, :has_key?, :dig
|
9
9
|
|
10
10
|
EXCHANGE_OPTION_DEFAULTS = {
|
11
11
|
:type => :direct,
|
@@ -84,8 +84,12 @@ module Sneakers
|
|
84
84
|
|
85
85
|
def self.configure_queue(name, opts)
|
86
86
|
retry_name = opts.fetch(:retry_exchange, "#{name}-retry")
|
87
|
-
opt_args = opts
|
88
|
-
|
87
|
+
opt_args = if opts.dig(:queue_options, :arguments).blank?
|
88
|
+
{}
|
89
|
+
else
|
90
|
+
opts.dig(:queue_options, :arguments).transform_keys(&:to_sym)
|
91
|
+
end
|
92
|
+
opts[:queue_options][:arguments] = { :'x-dead-letter-exchange' => retry_name }.merge!(opt_args)
|
89
93
|
opts[:queue_options]
|
90
94
|
end
|
91
95
|
|
data/lib/sneakers/publisher.rb
CHANGED
@@ -6,9 +6,6 @@ module Sneakers
|
|
6
6
|
def initialize(opts = {})
|
7
7
|
@mutex = Mutex.new
|
8
8
|
@opts = Sneakers::CONFIG.merge(opts)
|
9
|
-
# If we've already got a bunny object, use it. This allows people to
|
10
|
-
# specify all kinds of options we don't need to know about (e.g. for ssl).
|
11
|
-
@bunny = @opts[:connection]
|
12
9
|
end
|
13
10
|
|
14
11
|
def publish(msg, options = {})
|
@@ -29,8 +26,15 @@ module Sneakers
|
|
29
26
|
|
30
27
|
private
|
31
28
|
def connect!
|
32
|
-
|
33
|
-
|
29
|
+
# If we've already got a bunny object, use it. This allows people to
|
30
|
+
# specify all kinds of options we don't need to know about (e.g. for ssl).
|
31
|
+
@bunny = @opts[:connection]
|
32
|
+
if @bunny.respond_to?(:call)
|
33
|
+
@bunny = @bunny.call
|
34
|
+
else
|
35
|
+
@bunny ||= create_bunny_connection
|
36
|
+
@bunny.start
|
37
|
+
end
|
34
38
|
@channel = @bunny.create_channel
|
35
39
|
@exchange = @channel.exchange(@opts[:exchange], **@opts[:exchange_options])
|
36
40
|
end
|
data/lib/sneakers/queue.rb
CHANGED
@@ -19,8 +19,12 @@ class Sneakers::Queue
|
|
19
19
|
# If we've already got a bunny object, use it. This allows people to
|
20
20
|
# specify all kinds of options we don't need to know about (e.g. for ssl).
|
21
21
|
@bunny = @opts[:connection]
|
22
|
-
@bunny
|
23
|
-
|
22
|
+
if @bunny.respond_to?(:call)
|
23
|
+
@bunny = @bunny.call
|
24
|
+
else
|
25
|
+
@bunny ||= create_bunny_connection
|
26
|
+
@bunny.start
|
27
|
+
end
|
24
28
|
|
25
29
|
@channel = @bunny.create_channel
|
26
30
|
@channel.prefetch(@opts[:prefetch])
|
data/lib/sneakers/version.rb
CHANGED
@@ -122,19 +122,44 @@ describe Sneakers::Publisher do
|
|
122
122
|
durable: false
|
123
123
|
)
|
124
124
|
@existing_session = existing_session
|
125
|
+
@exchange = exchange
|
126
|
+
@channel = channel
|
125
127
|
end
|
126
128
|
|
127
|
-
it 'can handle an existing connection
|
129
|
+
it 'can handle an existing connection object' do
|
128
130
|
p = Sneakers::Publisher.new
|
129
131
|
p.publish('test msg', my_vars)
|
130
132
|
_(p.instance_variable_get(:@bunny)).must_equal @existing_session
|
131
133
|
end
|
132
134
|
|
135
|
+
it 'can handle an existing connection function' do
|
136
|
+
@existing_session.start
|
137
|
+
p = Sneakers::Publisher.new(connection: ->() { @existing_session })
|
138
|
+
p.publish('test msg', my_vars)
|
139
|
+
_(p.instance_variable_get(:@bunny)).must_equal @existing_session
|
140
|
+
end
|
141
|
+
|
133
142
|
it 'can handle an existing connection that is online' do
|
143
|
+
p = Sneakers::Publisher.new
|
144
|
+
p.publish('test msg', my_vars)
|
145
|
+
_(p.instance_variable_get(:@bunny)).must_equal @existing_session
|
134
146
|
mock(@existing_session).connected? { true }
|
147
|
+
mock(@exchange).publish('test msg 2', my_vars)
|
148
|
+
p.publish('test msg 2', my_vars)
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'can handle an existing connection that goes offline' do
|
135
152
|
p = Sneakers::Publisher.new
|
136
153
|
p.publish('test msg', my_vars)
|
137
154
|
_(p.instance_variable_get(:@bunny)).must_equal @existing_session
|
155
|
+
mock(@existing_session).connected? { false }
|
156
|
+
mock(@existing_session).start
|
157
|
+
mock(@existing_session).create_channel { @channel }
|
158
|
+
mock(@channel).exchange('another_exchange', type: :topic, durable: false, :auto_delete => false, arguments: { 'x-arg' => 'value' }) do
|
159
|
+
@exchange
|
160
|
+
end
|
161
|
+
mock(@exchange).publish('test msg 2', my_vars)
|
162
|
+
p.publish('test msg 2', my_vars)
|
138
163
|
end
|
139
164
|
end
|
140
165
|
|
data/spec/sneakers/queue_spec.rb
CHANGED
@@ -150,19 +150,24 @@ describe Sneakers::Queue do
|
|
150
150
|
:type => :direct,
|
151
151
|
:durable => true,
|
152
152
|
:arguments => { 'x-arg' => 'value' }){ @mkex }
|
153
|
-
|
154
|
-
|
155
|
-
mock(@mkchan).queue(queue_name, :durable => true) { @mkqueue }
|
156
|
-
mock(@mkqueue).bind(@mkex, :routing_key => queue_name)
|
153
|
+
mock(@mkchan).queue('foo', :durable => true) { @mkqueue }
|
154
|
+
mock(@mkqueue).bind(@mkex, :routing_key => 'foo')
|
157
155
|
mock(@mkqueue).subscribe(:block => false, :manual_ack => true)
|
158
|
-
|
159
|
-
my_vars = queue_vars.merge(:connection => @external_connection)
|
160
|
-
@q = Sneakers::Queue.new(queue_name, my_vars)
|
161
156
|
end
|
162
157
|
|
163
158
|
it 'uses that object' do
|
164
|
-
|
165
|
-
|
159
|
+
q = Sneakers::Queue.new('foo',
|
160
|
+
queue_vars.merge(:connection => @external_connection))
|
161
|
+
q.subscribe(@mkworker)
|
162
|
+
_(q.instance_variable_get(:@bunny)).must_equal @external_connection
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'uses that function' do
|
166
|
+
@external_connection.start
|
167
|
+
q = Sneakers::Queue.new('foo',
|
168
|
+
queue_vars.merge(:connection => ->() { @external_connection }))
|
169
|
+
q.subscribe(@mkworker)
|
170
|
+
_(q.instance_variable_get(:@bunny)).must_equal @external_connection
|
166
171
|
end
|
167
172
|
end
|
168
173
|
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kicks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dotan Nahum
|
8
8
|
- Michael Klishin
|
9
|
-
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2025-01-26 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: serverengine
|
@@ -343,7 +342,6 @@ licenses:
|
|
343
342
|
- MIT
|
344
343
|
metadata:
|
345
344
|
source_code_uri: https://github.com/ruby-amqp/kicks
|
346
|
-
post_install_message:
|
347
345
|
rdoc_options: []
|
348
346
|
require_paths:
|
349
347
|
- lib
|
@@ -358,8 +356,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
358
356
|
- !ruby/object:Gem::Version
|
359
357
|
version: '0'
|
360
358
|
requirements: []
|
361
|
-
rubygems_version: 3.
|
362
|
-
signing_key:
|
359
|
+
rubygems_version: 3.6.2
|
363
360
|
specification_version: 4
|
364
361
|
summary: Fast background processing framework for Ruby and RabbitMQ
|
365
362
|
test_files:
|