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 +4 -4
- data/lib/sidekiq-repeat.rb +3 -1
- data/lib/sidekiq/repeat.rb +10 -0
- data/lib/sidekiq/repeat/configuration.rb +31 -0
- data/lib/sidekiq/repeat/repeatable.rb +21 -19
- data/lib/sidekiq/repeat/version.rb +1 -1
- metadata +24 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4ff40d93c6daa63b523d3397831deac8ec94772
|
4
|
+
data.tar.gz: 246c9d8f2ff0f408a74d5d7db58667d175ca71ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5deeac2bb21d3e623df27f5b60e1c561417bd6af2283ecb42d30f7112a5b3c7ce47fe84c521bec0434bf4790ad5d5435db52a03553948a5e8ae285118947f1b8
|
7
|
+
data.tar.gz: cc125ebac8172201d4681d7220a791a03f2a405b8d1446edde9c73e0c6380947339bb9c400baff120f81e8b019c92c75b36b5f1a3db04240fe6744dd313fa563
|
data/lib/sidekiq-repeat.rb
CHANGED
data/lib/sidekiq/repeat.rb
CHANGED
@@ -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
|
-
|
14
|
-
return
|
15
|
-
|
16
|
-
ts
|
17
|
-
args =
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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.
|
34
|
+
@ss.find { |job| job.klass == self.name }
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
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.
|
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-
|
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:
|