tantot 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c2d99f4f8b4289301ef52256f0190d78b7fb2c3
4
- data.tar.gz: b827a5b307879a1682f9b9771b72bf11685d6850
3
+ metadata.gz: 8034dc47aeea3eeca0970dae7bec53a8e99de285
4
+ data.tar.gz: 26a50c7cd327edfdebc0706edf1cb6a861b76411
5
5
  SHA512:
6
- metadata.gz: a475eb7b2913b50b3ad68997b3d12352608301c20748f4c2cb6d8359111c87bb51448697257ddab34a770b3e618349e5a1ced6feceb9143f153779dc6f8541e5
7
- data.tar.gz: 61568c338ed951d8b367a803d307d321a33484c2c5d13d790ca70038c14a7f610d88e3adcefb42919006465a5e361cd0a3ecfc9f6086b4a92eea84f8da8e5498
6
+ metadata.gz: d439b688a52f03174b5f18020e226522518069da36e9b96b41953aec8266f8f81c533ae6299f5b4c496ffc9830512c7c62bb86b26075fe110627b135bfcd7119
7
+ data.tar.gz: a1a4189f19fdc39e248c40e3b4d60dc734dd4340082caeeb72289281df287aca115e84460714fce002ce49dea3195ff7c312caa5439693e5efb2663614a74bda
data/lib/tantot/config.rb CHANGED
@@ -2,13 +2,14 @@ module Tantot
2
2
  class Config
3
3
  include Singleton
4
4
 
5
- attr_accessor :performer, :format, :use_after_commit_callbacks, :sweep_on_push
5
+ attr_accessor :performer, :format, :use_after_commit_callbacks, :sweep_on_push, :sidekiq_queue
6
6
 
7
7
  def initialize
8
8
  @performer = :inline
9
9
  @format = :compact
10
10
  @use_after_commit_callbacks = true
11
11
  @sweep_on_push = false
12
+ @sidekiq_queue = :default
12
13
  end
13
14
  end
14
15
  end
@@ -11,8 +11,10 @@ module Tantot
11
11
  end
12
12
 
13
13
  def run(context, changes)
14
- context, changes = Tantot.collector.marshal(context, changes)
15
- Tantot::Performer::Sidekiq::Worker.perform_async(context, changes)
14
+ queue = context[:options][:queue] || Tantot.config.sidekiq_queue
15
+ ::Sidekiq::Client.push('class' => Tantot::Performer::Sidekiq::Worker,
16
+ 'args' => Tantot.collector.marshal(context, changes),
17
+ 'queue' => queue)
16
18
  end
17
19
  end
18
20
  end
@@ -1,3 +1,3 @@
1
1
  module Tantot
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -135,20 +135,6 @@ if defined?(::Chewy)
135
135
  City.create!
136
136
  end
137
137
  end
138
-
139
- if defined?(::Sidekiq)
140
- context "using Sidekiq" do
141
- require 'sidekiq/testing'
142
-
143
- around do |example|
144
- Sidekiq::Worker.clear_all
145
- Tantot.config.performer = :sidekiq
146
- example.run
147
- Tantot.config.performer = :inline
148
- end
149
- end
150
- end
151
-
152
138
  end
153
139
 
154
140
  end
data/spec/sidekiq_spec.rb CHANGED
@@ -31,6 +31,7 @@ if defined?(::Sidekiq)
31
31
  City.create name: 'foo'
32
32
  end
33
33
  expect(Tantot::Performer::Sidekiq::Worker.jobs.size).to eq(1)
34
+ expect(Tantot::Performer::Sidekiq::Worker.jobs.first["queue"]).to eq('default')
34
35
  expect(Tantot::Performer::Sidekiq::Worker.jobs.first["args"]).to eq([{
35
36
  "model" => "City",
36
37
  "attributes" => ["name"],
@@ -63,6 +64,7 @@ if defined?(::Sidekiq)
63
64
  city.save
64
65
  end
65
66
  expect(Tantot::Performer::Sidekiq::Worker.jobs.size).to eq(1)
67
+ expect(Tantot::Performer::Sidekiq::Worker.jobs.first["queue"]).to eq('default')
66
68
  expect(Tantot::Performer::Sidekiq::Worker.jobs.first["args"]).to eq([{
67
69
  "model" => "City",
68
70
  "attributes" => ["name"],
@@ -74,6 +76,55 @@ if defined?(::Sidekiq)
74
76
  end
75
77
  end
76
78
 
79
+ describe Tantot::Performer::Sidekiq do
80
+ context "with a specific queue on a watcher" do
81
+ before do
82
+ class SidekiqWatcher
83
+ include Tantot::Watcher
84
+
85
+ watcher_options queue: :foo
86
+
87
+ def perform(changes)
88
+ end
89
+ end
90
+
91
+ Sidekiq::Worker.clear_all
92
+ stub_model(:city) do
93
+ watch SidekiqWatcher, :name
94
+ end
95
+ end
96
+
97
+ it "should set the sidekiq queue accordingly" do
98
+ Tantot.collector.run do
99
+ City.create name: 'foo'
100
+ end
101
+ expect(Tantot::Performer::Sidekiq::Worker.jobs.size).to eq(1)
102
+ expect(Tantot::Performer::Sidekiq::Worker.jobs.first["queue"]).to eq('foo')
103
+ end
104
+ end
105
+
106
+ context "with a specific queue on a block" do
107
+ before do
108
+ Sidekiq::Worker.clear_all
109
+ stub_model(:city) do
110
+ watch(:name, queue: :foo) {|changes| }
111
+ end
112
+ end
113
+
114
+ it "should set the sidekiq queue accordingly" do
115
+ class SidekiqWatcher
116
+ watcher_options queue: :foo
117
+ end
118
+
119
+ Tantot.collector.run do
120
+ City.create name: 'foo'
121
+ end
122
+ expect(Tantot::Performer::Sidekiq::Worker.jobs.size).to eq(1)
123
+ expect(Tantot::Performer::Sidekiq::Worker.jobs.first["queue"]).to eq('foo')
124
+ end
125
+ end
126
+ end
127
+
77
128
  describe Tantot::Collector::Block do
78
129
  let(:value) { {changed: false} }
79
130
  let(:changes) { {obj: nil} }
@@ -93,6 +144,7 @@ if defined?(::Sidekiq)
93
144
  end
94
145
  expect(Tantot::Performer::Sidekiq::Worker.jobs.size).to eq(1)
95
146
  block_id = Tantot.registry.watch_config.keys.last
147
+ expect(Tantot::Performer::Sidekiq::Worker.jobs.first["queue"]).to eq('default')
96
148
  expect(Tantot::Performer::Sidekiq::Worker.jobs.first["args"]).to eq([{
97
149
  "model" => "City",
98
150
  "attributes" => ["name"],
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tantot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - François-Pierre Bouchard