sidekiq-cron 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -176,7 +176,7 @@ module Sidekiq
176
176
  @last_run_time = Time.parse(args['last_run_time'].to_s) rescue Time.now
177
177
 
178
178
  #get right arguments for job
179
- @args = args["args"].nil? ? [] : (args["args"].is_a?(Array) ? args["args"] : [ args["args"] ])
179
+ @args = args["args"].nil? ? [] : parse_args( args["args"] )
180
180
 
181
181
  if args["message"]
182
182
  @message = args["message"]
@@ -266,7 +266,12 @@ module Sidekiq
266
266
  cron = CronParser.new(@cron)
267
267
  cron.next(Time.now)
268
268
  rescue Exception => e
269
- errors << "'cron' -> #{@cron}: #{e.message}"
269
+ #fix for different versions of cron-parser
270
+ if e.message == "Bad Vixie-style specification bad"
271
+ errors << "'cron' -> #{@cron}: not a valid cronline"
272
+ else
273
+ errors << "'cron' -> #{@cron}: #{e.message}"
274
+ end
270
275
  end
271
276
  end
272
277
 
@@ -359,6 +364,25 @@ module Sidekiq
359
364
 
360
365
  private
361
366
 
367
+ # Try parsing inbound args into an array.
368
+ # args from Redis will be encoded JSON;
369
+ # try to load JSON, then failover
370
+ # to string array.
371
+ def parse_args(args)
372
+ case args
373
+ when String
374
+ begin
375
+ Sidekiq.load_json(args)
376
+ rescue JSON::ParserError
377
+ [*args] # cast to string array
378
+ end
379
+ when Array
380
+ args # do nothing, already array
381
+ else
382
+ [*args] # cast to string array
383
+ end
384
+ end
385
+
362
386
  # Redis key for set of all cron jobs
363
387
  def self.jobs_key
364
388
  "cron_jobs"
data/sidekiq-cron.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "sidekiq-cron"
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ondrej Bartas"]
12
- s.date = "2013-08-30"
12
+ s.date = "2013-09-07"
13
13
  s.description = "Enables to set jobs to be run in specified time (using CRON notation)"
14
14
  s.email = "ondrej@bartas.cz"
15
15
  s.extra_rdoc_files = [
@@ -292,6 +292,45 @@ class CronJobTest < Test::Unit::TestCase
292
292
  end
293
293
  end
294
294
 
295
+ context "initialize args" do
296
+ should "from JSON" do
297
+ args = {
298
+ name: "Test",
299
+ cron: "* * * * *",
300
+ klass: "CronTestClass",
301
+ args: JSON.dump(["123"])
302
+ }
303
+ Sidekiq::Cron::Job.new(args).tap do |job|
304
+ assert_equal job.args, ["123"]
305
+ assert_equal job.name, "Test"
306
+ end
307
+ end
308
+ should "from String" do
309
+ args = {
310
+ name: "Test",
311
+ cron: "* * * * *",
312
+ klass: "CronTestClass",
313
+ args: "(my funny string)"
314
+ }
315
+ Sidekiq::Cron::Job.new(args).tap do |job|
316
+ assert_equal job.args, ["(my funny string)"]
317
+ assert_equal job.name, "Test"
318
+ end
319
+ end
320
+ should "from Array" do
321
+ args = {
322
+ name: "Test",
323
+ cron: "* * * * *",
324
+ klass: "CronTestClass",
325
+ args: ["This is array"]
326
+ }
327
+ Sidekiq::Cron::Job.new(args).tap do |job|
328
+ assert_equal job.args, ["This is array"]
329
+ assert_equal job.name, "Test"
330
+ end
331
+ end
332
+ end
333
+
295
334
  context "create & find methods" do
296
335
  setup do
297
336
  @args = {
@@ -485,7 +524,7 @@ class CronJobTest < Test::Unit::TestCase
485
524
  @jobs_hash['name_of_job']['cron'] = "bad cron"
486
525
  out = Sidekiq::Cron::Job.load_from_hash @jobs_hash
487
526
  assert_equal out.size, 1, "should have 1 error"
488
- assert_equal out, {"name_of_job"=>["'cron' -> bad cron: Bad Vixie-style specification bad"]}
527
+ assert_equal out, {"name_of_job"=>["'cron' -> bad cron: not a valid cronline"]}
489
528
  assert_equal Sidekiq::Cron::Job.all.size, 1, "Should have only 1 job after load"
490
529
  end
491
530
 
@@ -526,4 +565,4 @@ class CronJobTest < Test::Unit::TestCase
526
565
  end
527
566
  end
528
567
  end
529
- end
568
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-cron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
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: 2013-08-30 00:00:00.000000000 Z
12
+ date: 2013-09-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sidekiq
@@ -298,7 +298,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
298
298
  version: '0'
299
299
  segments:
300
300
  - 0
301
- hash: 4034147313320020795
301
+ hash: 2947287720654605412
302
302
  required_rubygems_version: !ruby/object:Gem::Requirement
303
303
  none: false
304
304
  requirements: