sidekiq-cron 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -4,6 +4,9 @@ rvm:
4
4
  - jruby-19mode
5
5
  - rbx-19mode
6
6
  - 2.0.0
7
+ - 2.1.0
8
+ services:
9
+ - redis-server
7
10
  branches:
8
11
  only:
9
12
  - master
@@ -16,5 +19,4 @@ env:
16
19
  matrix:
17
20
  allow_failures:
18
21
  - rvm: jruby-19mode
19
- - rvm: rbx-19mode
20
- - rvm: 2.0.0
22
+ - rvm: rbx-19mode
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem "sidekiq", ">= 2.16.0"
3
+ gem "sidekiq", ">= 2.17.3"
4
4
  gem 'rufus-scheduler', '>= 2.0.24'
5
5
 
6
6
  group :development do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.8
1
+ 0.1.9
@@ -15,18 +15,14 @@ module Sidekiq
15
15
 
16
16
  #crucial part of whole enquing job
17
17
  def should_enque? time
18
- out = false
19
- Sidekiq.redis do |conn|
20
- out = (
21
- status == "enabled" &&
22
- @last_run_time < last_time(time) &&
23
- conn.zadd(job_enqueued_key, time.to_f.to_s, formated_last_time(time) )
24
- )
18
+ enqueue = false
19
+ enqueue = Sidekiq.redis do |conn|
20
+ status == "enabled" && not_enqueued_after?(time) && conn.zadd(job_enqueued_key, time.to_f.to_s, formated_last_time(time))
25
21
  end
26
- out
22
+ enqueue
27
23
  end
28
24
 
29
- # remove previous informations about run times
25
+ # remove previous informations about run times
30
26
  # this will clear redis and make sure that redis will
31
27
  # not overflow with memory
32
28
  def remove_previous_enques time
@@ -47,7 +43,6 @@ module Sidekiq
47
43
 
48
44
  #enque cron job to queue
49
45
  def enque! time = Time.now
50
- @last_run_time = time
51
46
  @last_enqueue_time = time
52
47
 
53
48
  Sidekiq::Client.push(@message.is_a?(String) ? Sidekiq.load_json(@message) : @message)
@@ -159,7 +154,7 @@ module Sidekiq
159
154
  end
160
155
 
161
156
  attr_accessor :name, :cron, :klass, :args, :message
162
- attr_reader :last_run_time, :last_enqueue_time
157
+ attr_reader :last_enqueue_time
163
158
 
164
159
  def initialize input_args = {}
165
160
  args = input_args.stringify_keys
@@ -173,9 +168,9 @@ module Sidekiq
173
168
  #set status of job
174
169
  @status = args['status'] || status_from_redis
175
170
 
176
- #set last run time
177
- @last_run_time = Time.parse(args['last_run_time'].to_s) rescue Time.now
178
- @last_enqueue_time = Time.parse(args['last_enqueue_time'].to_s) rescue nil
171
+ if args['last_enqueue_time'] && !args['last_enqueue_time'].empty?
172
+ @last_enqueue_time = Time.parse(args['last_enqueue_time'])
173
+ end
179
174
 
180
175
  #get right arguments for job
181
176
  @args = args["args"].nil? ? [] : parse_args( args["args"] )
@@ -248,7 +243,6 @@ module Sidekiq
248
243
  args: @args.is_a?(String) ? @args : Sidekiq.dump_json(@args || []),
249
244
  message: @message.is_a?(String) ? @message : Sidekiq.dump_json(@message || {}),
250
245
  status: @status,
251
- last_run_time: @last_run_time,
252
246
  last_enqueue_time: @last_enqueue_time,
253
247
  }
254
248
  end
@@ -361,9 +355,13 @@ module Sidekiq
361
355
  def sort_name
362
356
  "#{status == "enabled" ? 0 : 1}_#{name}".downcase
363
357
  end
364
-
358
+
365
359
  private
366
360
 
361
+ def not_enqueued_after?(time)
362
+ @last_enqueue_time.nil? || @last_enqueue_time < last_time(time)
363
+ end
364
+
367
365
  # Try parsing inbound args into an array.
368
366
  # args from Redis will be encoded JSON;
369
367
  # try to load JSON, then failover
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.8"
8
+ s.version = "0.1.9"
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-11-29"
12
+ s.date = "2014-01-27"
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 = [
@@ -53,7 +53,7 @@ Gem::Specification.new do |s|
53
53
  s.specification_version = 3
54
54
 
55
55
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
- s.add_runtime_dependency(%q<sidekiq>, [">= 2.16.0"])
56
+ s.add_runtime_dependency(%q<sidekiq>, [">= 2.17.3"])
57
57
  s.add_runtime_dependency(%q<rufus-scheduler>, [">= 2.0.24"])
58
58
  s.add_development_dependency(%q<bundler>, [">= 0"])
59
59
  s.add_development_dependency(%q<simplecov>, [">= 0"])
@@ -69,7 +69,7 @@ Gem::Specification.new do |s|
69
69
  s.add_development_dependency(%q<coveralls>, [">= 0"])
70
70
  s.add_development_dependency(%q<shotgun>, [">= 0"])
71
71
  else
72
- s.add_dependency(%q<sidekiq>, [">= 2.16.0"])
72
+ s.add_dependency(%q<sidekiq>, [">= 2.17.3"])
73
73
  s.add_dependency(%q<rufus-scheduler>, [">= 2.0.24"])
74
74
  s.add_dependency(%q<bundler>, [">= 0"])
75
75
  s.add_dependency(%q<simplecov>, [">= 0"])
@@ -86,7 +86,7 @@ Gem::Specification.new do |s|
86
86
  s.add_dependency(%q<shotgun>, [">= 0"])
87
87
  end
88
88
  else
89
- s.add_dependency(%q<sidekiq>, [">= 2.16.0"])
89
+ s.add_dependency(%q<sidekiq>, [">= 2.17.3"])
90
90
  s.add_dependency(%q<rufus-scheduler>, [">= 2.0.24"])
91
91
  s.add_dependency(%q<bundler>, [">= 0"])
92
92
  s.add_dependency(%q<simplecov>, [">= 0"])
@@ -20,6 +20,7 @@ class CronJobTest < Test::Unit::TestCase
20
20
 
21
21
  should "be initialized" do
22
22
  job = Sidekiq::Cron::Job.new()
23
+ assert_nil job.last_enqueue_time
23
24
  assert job.is_a?(Sidekiq::Cron::Job)
24
25
  end
25
26
 
@@ -109,8 +110,8 @@ class CronJobTest < Test::Unit::TestCase
109
110
  end
110
111
 
111
112
  should "have to_hash method" do
112
- [:name,:klass,:cron,:args,:message,:status, :last_run_time].each do |key|
113
- assert @job.to_hash.has_key?(key), "to_hash must have key: #{key}"
113
+ [:name,:klass,:cron,:args,:message,:status].each do |key|
114
+ assert @job.to_hash.has_key?(key), "to_hash must have key: #{key}"
114
115
  end
115
116
  end
116
117
  end
@@ -467,7 +468,11 @@ class CronJobTest < Test::Unit::TestCase
467
468
  end
468
469
 
469
470
  should "remove old enque times + should be enqeued" do
470
- assert Sidekiq::Cron::Job.new(@args).test_and_enque_for_time!(@time), "should enqueue"
471
+ job = Sidekiq::Cron::Job.new(@args)
472
+ assert_nil job.last_enqueue_time
473
+ assert job.test_and_enque_for_time!(@time), "should enqueue"
474
+ assert job.last_enqueue_time
475
+
471
476
  refute Sidekiq::Cron::Job.new(@args).test_and_enque_for_time!(@time), "should not enqueue"
472
477
  Sidekiq.redis do |conn|
473
478
  assert_equal conn.zcard(Sidekiq::Cron::Job.new(@args).send(:job_enqueued_key)), 2, "Should have two enqueued job (first was in save, second in enque)"
@@ -1,13 +1,14 @@
1
1
  require './test/test_helper'
2
2
 
3
3
  class CronWebExtensionTest < Test::Unit::TestCase
4
+
5
+ def app
6
+ Sidekiq::Web
7
+ end
8
+
4
9
  context 'Cron web' do
5
10
  include Rack::Test::Methods
6
11
 
7
- def app
8
- Sidekiq::Web
9
- end
10
-
11
12
  setup do
12
13
  Sidekiq.redis = REDIS
13
14
  Sidekiq.redis {|c| c.flushdb }
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.8
4
+ version: 0.1.9
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-11-29 00:00:00.000000000 Z
12
+ date: 2014-01-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sidekiq
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 2.16.0
21
+ version: 2.17.3
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 2.16.0
29
+ version: 2.17.3
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rufus-scheduler
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -299,7 +299,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
299
299
  version: '0'
300
300
  segments:
301
301
  - 0
302
- hash: -1914216490910981092
302
+ hash: -890325318725409661
303
303
  required_rubygems_version: !ruby/object:Gem::Requirement
304
304
  none: false
305
305
  requirements: