sidekiq-repeat 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 555a748fae5d290be3bb712ab440479dacf0c9fe
4
- data.tar.gz: 8e2c7552fc996199993c6cfee732f094e2d8eb22
3
+ metadata.gz: e4ff40d93c6daa63b523d3397831deac8ec94772
4
+ data.tar.gz: 246c9d8f2ff0f408a74d5d7db58667d175ca71ff
5
5
  SHA512:
6
- metadata.gz: d0f3e27069e456a46df3d0c9bf0e805c2572e1fe322ce252ea958f9aac386e88e945bccee700ba88e8046f6ec6e9942e7e53ac8faef1158131c14d28773c99df
7
- data.tar.gz: 1ebb70fed3d51399368fbb7a67e566e6431751d06e3662884fd0fb654ad8d5a07ae2c6d2a640b59e725d7edfe84cbab39370d82271ab289f22c1734152a52358
6
+ metadata.gz: 5deeac2bb21d3e623df27f5b60e1c561417bd6af2283ecb42d30f7112a5b3c7ce47fe84c521bec0434bf4790ad5d5435db52a03553948a5e8ae285118947f1b8
7
+ data.tar.gz: cc125ebac8172201d4681d7220a791a03f2a405b8d1446edde9c73e0c6380947339bb9c400baff120f81e8b019c92c75b36b5f1a3db04240fe6744dd313fa563
@@ -6,6 +6,8 @@ Sidekiq.configure_server do |config|
6
6
  end
7
7
 
8
8
  config.on(:startup) do
9
- Sidekiq::Repeat::Repeatable.reschedule_all
9
+ Sidekiq::Repeat::Configuration.with_lock do
10
+ Sidekiq::Repeat::Repeatable.reschedule_all
11
+ end
10
12
  end
11
13
  end
@@ -1,8 +1,18 @@
1
1
  require 'parse-cron'
2
+ require 'redlock'
2
3
  require 'sidekiq'
3
4
  require 'sidekiq/api'
4
5
 
6
+ require 'sidekiq/repeat/configuration'
5
7
  require 'sidekiq/repeat/middleware'
6
8
  require 'sidekiq/repeat/mini_ice_cube'
7
9
  require 'sidekiq/repeat/repeatable'
8
10
  require 'sidekiq/repeat/version'
11
+
12
+ module Sidekiq
13
+ module Repeat
14
+ def self.configure
15
+ yield Configuration.instance
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,31 @@
1
+ require 'singleton'
2
+
3
+ module Sidekiq
4
+ module Repeat
5
+ class Configuration
6
+ include Singleton
7
+
8
+ def initialize
9
+ reset_to_default!
10
+ end
11
+
12
+ def reset_to_default!
13
+ @redlock_enabled = true
14
+ @redlock_redis_instances = ['redis://localhost:6379']
15
+ end
16
+
17
+ attr_accessor :redlock_enabled
18
+ attr_accessor :redlock_redis_instances
19
+
20
+ def self.with_lock
21
+ if instance.redlock_enabled
22
+ Redlock::Client.new(instance.redlock_redis_instances).lock('sidekiq-repeat-reschedule-all', 500) do
23
+ yield
24
+ end
25
+ else
26
+ yield
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -10,26 +10,28 @@ module Sidekiq
10
10
  end
11
11
 
12
12
  def reschedule
13
- return unless repeat_configured?
14
- return if already_scheduled?
15
-
16
- ts = @cronline.next
17
- args = repeat_arguments(ts)
18
- self.perform_at ts.to_f, *args
19
- Sidekiq.logger.info "Scheduled #{self.name} for #{ts}."
20
- end
21
-
22
- def repeat_arguments(ts)
23
- [Time.now.to_f, ts.to_f].compact.take(instance_method(:perform).arity)
24
- end
25
-
26
- def repeat_configured?
27
- !!@cronline
28
- end
29
-
30
- def already_scheduled?
13
+ # Only if repeat is configured.
14
+ return unless !!@cronline
15
+
16
+ ts = @cronline.next
17
+ args = [Time.now.to_f, ts.to_f].take(instance_method(:perform).arity)
18
+ nj = next_scheduled_job
19
+
20
+ if nj
21
+ if nj.at > ts
22
+ nj.item['args'] = args
23
+ nj.reschedule ts.to_f
24
+ Sidekiq.logger.info "Re-scheduled #{self.name} for #{ts}."
25
+ end
26
+ else
27
+ self.perform_at ts.to_f, *args
28
+ Sidekiq.logger.info "Scheduled #{self.name} for #{ts}."
29
+ end
30
+ end
31
+
32
+ def next_scheduled_job
31
33
  @ss ||= Sidekiq::ScheduledSet.new
32
- @ss.any? { |job| job.klass == self.name }
34
+ @ss.find { |job| job.klass == self.name }
33
35
  end
34
36
  end
35
37
 
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Repeat
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-repeat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - FlavourSys Technology GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-13 00:00:00.000000000 Z
11
+ date: 2015-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -38,6 +38,26 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: redlock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 0.1.1
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.1.1
41
61
  - !ruby/object:Gem::Dependency
42
62
  name: minitest
43
63
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +95,7 @@ extra_rdoc_files: []
75
95
  files:
76
96
  - lib/sidekiq-repeat.rb
77
97
  - lib/sidekiq/repeat.rb
98
+ - lib/sidekiq/repeat/configuration.rb
78
99
  - lib/sidekiq/repeat/middleware.rb
79
100
  - lib/sidekiq/repeat/mini_ice_cube.rb
80
101
  - lib/sidekiq/repeat/repeatable.rb
@@ -104,3 +125,4 @@ signing_key:
104
125
  specification_version: 4
105
126
  summary: Repeat is a clockless recurring job system for Sidekiq.
106
127
  test_files: []
128
+ has_rdoc: