sidekiq-client-cli 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTgyYzgzOGEyYzEwMGJhM2FiNGNjZDE0NDFmN2U4ZjQ2YTIzMGUxYg==
4
+ YmU4MTg4ZWJlZjFiOTU3NjVkNWEyYWYyYWZhMjY1ZDJmMThiZGMyOA==
5
5
  data.tar.gz: !binary |-
6
- ZTdiZDI4YTNkYTZlM2Y4ZWJjOTM1MzU4ZDg1MWQyMzNmNTQyODQ5NA==
6
+ NzZiMTBlODYyZGEyMTExNzJiMDBiNjU4YmQwNWFkY2Y0ODdmMGMxMA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NWVkODk5YzcwMDE2Y2Y0NTY4NmY4Mjc3NmRmMDBmNDk5ZDBhYTBmNjVlMDZh
10
- MGUzNGRlOGU1YTIyYzdhYmM2YzhkYzExNWE0ZGE2ZGMyZGI5ZTJkYWYxMWY0
11
- MWMwZDJkMmMyZDEyYzRiN2U5MWIwOWJjMzNjYWE0NDhkNjFiMGU=
9
+ NWViYTdhZGM4ODNjZDE4ZWYxNTY0Yjk5ZjM1ZDM3YzJiMTBkNWU3ZDkxODk5
10
+ YmVkNGVjNjZmNzk2ZDhmMzkyMGVjOWVmZmI4MTljYzRlNTAxYjY3MjI1ODU5
11
+ OWZhOWZlMjFlYWM4NDFiMWZiNGE4NDQ1Yjc4MDliNDMzODVlMzk=
12
12
  data.tar.gz: !binary |-
13
- NzdmMDU3Y2YyMTE0N2U0NTZmMTVkMGM2Y2MzYjAwYjY2MmNkYjVhY2QzOTM4
14
- NTAzNmQ0ZWE0NWQxMzI3N2NiMTRkNzZmYTE4ZjZiM2I3Y2I5OTk5NjEwMTQ2
15
- NDk2NzFjOWY3MzE1MGMxNzM2ZGU1ZWIzZjQ1ZmMxZjM5ZmUzODk=
13
+ ODk5Y2Q5OGFjYmFmODM2Yzk2M2Q1NmYxYTRjMjI1MDFlYWQ0OTczOWFmOTE4
14
+ NTM4NDVhMmRiNGE4ZGEwZWU1MjMwM2M4OWU3ZDNiMDk0MjU3Njk0YzMzZjc3
15
+ ZDJjZTQwOTgyNzViMzE0MDllMzQ4NzNhMDU1Y2E0Y2U4N2E1ZDQ=
data/README.md CHANGED
@@ -37,6 +37,14 @@ You can also specify a specific queue to push the jobs to :
37
37
 
38
38
  $ sidekiq-client -q my_queue push MyWorker OtherWorker
39
39
 
40
+ You can specify that the job should not be retried, if it fails :
41
+
42
+ $ sidekiq-client -r false push MyWorker OtherWorker
43
+
44
+ You can also specify the number of times a job should be retried, if it fails :
45
+
46
+ $ sidekiq-client -r 5 push MyWorker OtherWorker
47
+
40
48
  For help :
41
49
 
42
50
  $ sidekiq-client --help
@@ -12,6 +12,7 @@ class SidekiqClientCLI
12
12
  @settings = CLI.new do
13
13
  option :config_path, :short => :c, :default => DEFAULT_CONFIG_PATH, :description => "Sidekiq client config file path"
14
14
  option :queue, :short => :q, :description => "Queue to place job on"
15
+ option :retry, :short => :r, :cast => lambda { |r| SidekiqClientCLI.cast_retry_option(r) }, :description => "Retry option for job"
15
16
  argument :command, :description => "'push' to push a job to the queue"
16
17
  arguments :command_args, :required => false, :description => "command arguments"
17
18
  end.parse! do |settings|
@@ -23,12 +24,19 @@ class SidekiqClientCLI
23
24
  end
24
25
  end
25
26
 
27
+ def self.cast_retry_option(retry_option)
28
+ return true if !!retry_option.match(/^(true|t|yes|y)$/i)
29
+ return false if !!retry_option.match(/^(false|f|no|n|0)$/i)
30
+ return retry_option.to_i if !!retry_option.match(/^\d+$/)
31
+ end
32
+
26
33
  def run
27
34
  # load the config file
28
35
  load settings.config_path if File.exists?(settings.config_path)
29
36
 
30
- # set queue if not given
37
+ # set queue or retry if they are not given
31
38
  settings.queue ||= Sidekiq.default_worker_options['queue']
39
+ settings.retry ||= Sidekiq.default_worker_options['retry']
32
40
 
33
41
  self.send settings.command.to_sym
34
42
  end
@@ -36,8 +44,11 @@ class SidekiqClientCLI
36
44
  def push
37
45
  settings.command_args.each do |arg|
38
46
  begin
39
- jid = Sidekiq::Client.push('class' => arg, 'queue' => settings.queue, 'args' => [])
40
- p "Posted #{arg} to queue '#{settings.queue}', Job ID : #{jid}"
47
+ jid = Sidekiq::Client.push({ 'class' => arg,
48
+ 'queue' => settings.queue,
49
+ 'args' => [],
50
+ 'retry' => settings.retry })
51
+ p "Posted #{arg} to queue '#{settings.queue}', Job ID : #{jid}, Retry : #{settings.retry}"
41
52
  rescue StandardError => ex
42
53
  p "Failed to push to queue : #{ex.message}"
43
54
  end
@@ -1,3 +1,3 @@
1
1
  class SidekiqClientCLI
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -2,6 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe SidekiqClientCLI do
4
4
  let(:default_queue) { Sidekiq.default_worker_options['queue'] }
5
+ let(:default_retry_option) { Sidekiq.default_worker_options['retry'] }
5
6
 
6
7
  before(:each) { @client = SidekiqClientCLI.new }
7
8
 
@@ -47,6 +48,7 @@ describe SidekiqClientCLI do
47
48
  @client.settings.command_args.should eq worker_klasses
48
49
  @client.settings.config_path.should eq SidekiqClientCLI::DEFAULT_CONFIG_PATH
49
50
  @client.settings.queue.should eq nil
51
+ @client.settings.retry.should eq nil
50
52
  end
51
53
 
52
54
  it "parses push with a configuration file" do
@@ -69,6 +71,26 @@ describe SidekiqClientCLI do
69
71
  @client.settings.queue.should eq "my_queue"
70
72
  end
71
73
 
74
+ it 'parses push with a boolean retry' do
75
+ worker_klasses = %w{FirstWorker SecondWorker}
76
+ ARGV = %w{ -r false push }.concat(worker_klasses)
77
+ @client.parse
78
+ @client.settings.command.should eq "push"
79
+ @client.settings.command_args.should eq worker_klasses
80
+ @client.settings.config_path.should eq SidekiqClientCLI::DEFAULT_CONFIG_PATH
81
+ @client.settings.retry.should eq false
82
+ end
83
+
84
+ it 'parses push with an integer retry' do
85
+ worker_klasses = %w{FirstWorker SecondWorker}
86
+ ARGV = %w{ -r 42 push }.concat(worker_klasses)
87
+ @client.parse
88
+ @client.settings.command.should eq "push"
89
+ @client.settings.command_args.should eq worker_klasses
90
+ @client.settings.config_path.should eq SidekiqClientCLI::DEFAULT_CONFIG_PATH
91
+ @client.settings.retry.should eq 42
92
+ end
93
+
72
94
  end
73
95
 
74
96
  describe "run" do
@@ -78,6 +100,7 @@ describe SidekiqClientCLI do
78
100
  @client.settings.stub(:config_path).and_return(config_path)
79
101
  @client.settings.stub(:command).and_return("mycommand")
80
102
  @client.settings.stub(:queue).and_return(default_queue)
103
+ @client.settings.stub(:retry).and_return(default_retry_option)
81
104
  @client.should_receive(:mycommand)
82
105
 
83
106
  File.should_receive(:exists?).with(config_path).and_return true
@@ -86,12 +109,13 @@ describe SidekiqClientCLI do
86
109
  @client.run
87
110
  end
88
111
 
89
- it "loads the config file if existing and runs the command" do
112
+ it "won't load a non-existant config file and the command is run" do
90
113
  config_path = "sidekiq.conf"
91
114
  settings = double("settings")
92
115
  settings.stub(:config_path).and_return(config_path)
93
116
  settings.stub(:command).and_return("mycommand")
94
117
  settings.stub(:queue).and_return(default_queue)
118
+ settings.stub(:retry).and_return(default_retry_option)
95
119
 
96
120
  @client.settings = settings
97
121
  @client.should_receive(:mycommand)
@@ -105,45 +129,97 @@ describe SidekiqClientCLI do
105
129
  end
106
130
 
107
131
  describe 'push' do
108
- it "pushes the worker classes" do
109
- klass1 = "FirstWorker"
110
- klass2 = "SecondWorker"
111
- settings = double("settings")
132
+ let(:settings) { double("settings") }
133
+ let(:klass1) { "FirstWorker" }
134
+ let(:klass2) { "SecondWorker" }
135
+
136
+ before(:each) do
112
137
  settings.stub(:command_args).and_return [klass1, klass2]
138
+ end
139
+
140
+ it "pushes the worker classes" do
113
141
  settings.stub(:queue).and_return default_queue
142
+ settings.stub(:retry).and_return default_retry_option
114
143
  @client.settings = settings
115
-
116
- Sidekiq::Client.should_receive(:push).with('class' => klass1, 'args' => [], 'queue' => default_queue)
117
- Sidekiq::Client.should_receive(:push).with('class' => klass2, 'args' => [], 'queue' => default_queue)
144
+ Sidekiq::Client.should_receive(:push).with('class' => klass1,
145
+ 'args' => [],
146
+ 'queue' => default_queue,
147
+ 'retry' => default_retry_option)
148
+ Sidekiq::Client.should_receive(:push).with('class' => klass2,
149
+ 'args' => [],
150
+ 'queue' => default_queue,
151
+ 'retry' => default_retry_option)
118
152
 
119
153
  @client.push
120
154
  end
121
155
 
122
156
  it "pushes the worker classes to the correct queue" do
123
157
  queue = "Queue"
124
- klass1 = "FirstWorker"
125
- klass2 = "SecondWorker"
126
- settings = double("settings")
127
- settings.stub(:command_args).and_return [klass1, klass2]
128
158
  settings.stub(:queue).and_return queue
159
+ settings.stub(:retry).and_return default_retry_option
129
160
  @client.settings = settings
130
161
 
131
- Sidekiq::Client.should_receive(:push).with('class' => klass1, 'args' => [], 'queue' => queue)
132
- Sidekiq::Client.should_receive(:push).with('class' => klass2, 'args' => [], 'queue' => queue)
162
+ Sidekiq::Client.should_receive(:push).with('class' => klass1,
163
+ 'args' => [],
164
+ 'queue' => queue,
165
+ 'retry' => default_retry_option)
166
+ Sidekiq::Client.should_receive(:push).with('class' => klass2,
167
+ 'args' => [],
168
+ 'queue' => queue,
169
+ 'retry' => default_retry_option)
170
+
171
+ @client.push
172
+ end
173
+
174
+ it 'pushes the worker classes with retry disabled' do
175
+ retry_option = false
176
+ settings.stub(:queue).and_return default_queue
177
+ settings.stub(:retry).and_return retry_option
178
+ @client.settings = settings
179
+
180
+ Sidekiq::Client.should_receive(:push).with('class' => klass1,
181
+ 'args' => [],
182
+ 'queue' => default_queue,
183
+ 'retry' => retry_option)
184
+ Sidekiq::Client.should_receive(:push).with('class' => klass2,
185
+ 'args' => [],
186
+ 'queue' => default_queue,
187
+ 'retry' => retry_option)
188
+
189
+ @client.push
190
+ end
191
+
192
+ it 'pushes the worker classes with a set retry number' do
193
+ retry_attempts = 5
194
+ settings.stub(:queue).and_return default_queue
195
+ settings.stub(:retry).and_return retry_attempts
196
+ @client.settings = settings
197
+
198
+ Sidekiq::Client.should_receive(:push).with('class' => klass1,
199
+ 'args' => [],
200
+ 'queue' => default_queue,
201
+ 'retry' => retry_attempts)
202
+ Sidekiq::Client.should_receive(:push).with('class' => klass2,
203
+ 'args' => [],
204
+ 'queue' => default_queue,
205
+ 'retry' => retry_attempts)
133
206
 
134
207
  @client.push
135
208
  end
136
209
 
137
210
  it "prints and continues if an exception is raised" do
138
- klass1 = "FirstWorker"
139
- klass2 = "SecondWorker"
140
- settings = double("settings")
141
- settings.stub(:command_args).and_return [klass1, klass2]
142
211
  settings.stub(:queue).and_return default_queue
212
+ settings.stub(:retry).and_return default_retry_option
143
213
  @client.settings = settings
144
214
 
145
- Sidekiq::Client.should_receive(:push).with('class' => klass1, 'args' => [], 'queue' => default_queue).and_raise
146
- Sidekiq::Client.should_receive(:push).with('class' => klass2, 'args' => [], 'queue' => default_queue)
215
+ Sidekiq::Client.should_receive(:push).with('class' => klass1,
216
+ 'args' => [],
217
+ 'queue' => default_queue,
218
+ 'retry' => default_retry_option).and_raise
219
+ Sidekiq::Client.should_receive(:push).with('class' => klass2,
220
+ 'args' => [],
221
+ 'queue' => default_queue,
222
+ 'retry' => default_retry_option)
147
223
 
148
224
  out = IOHelper.stdout_read do
149
225
  @client.push
@@ -153,4 +229,29 @@ describe SidekiqClientCLI do
153
229
 
154
230
  end
155
231
 
232
+ describe 'cast_retry_option' do
233
+ subject { SidekiqClientCLI }
234
+
235
+ it 'returns false if the string matches false|f|no|n|0' do
236
+ subject.cast_retry_option('false').should == false
237
+ subject.cast_retry_option('f').should == false
238
+ subject.cast_retry_option('no').should == false
239
+ subject.cast_retry_option('n').should == false
240
+ subject.cast_retry_option('0').should == false
241
+ end
242
+
243
+ it 'returns true if the string matches true|t|yes|y' do
244
+ subject.cast_retry_option('true').should == true
245
+ subject.cast_retry_option('t').should == true
246
+ subject.cast_retry_option('yes').should == true
247
+ subject.cast_retry_option('y').should == true
248
+ end
249
+
250
+ it 'returns an integer if the passed string is an integer' do
251
+ subject.cast_retry_option('1').should == 1
252
+ subject.cast_retry_option('42').should == 42
253
+ end
254
+
255
+ end
256
+
156
257
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-client-cli
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
  - Adil Haritah
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-04 00:00:00.000000000 Z
11
+ date: 2013-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler