sidekiq-repeat 0.1.0 → 0.2.0

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
- SHA1:
3
- metadata.gz: 640363fb32bb0a5e6c6d7b9ce47109bb4d26244e
4
- data.tar.gz: 43481093dd233b479c4fa4c5809cee3b547911d2
2
+ SHA256:
3
+ metadata.gz: 1d46671c4ad696a61604b109d4b6fdb3971a2ed698c4f2533a8610efdc60e0db
4
+ data.tar.gz: f3c7c93ba4c3ce80849861bbf692d43cabcb3c1cf8aad6ad67740bb598c0e637
5
5
  SHA512:
6
- metadata.gz: 2957cc62da166c65fc5ea481a39a903d6a6e2a533aa3f4b0a81171a0975b9d0ce253b995bdd3d9a61b4e729d4d7cb1252c515346750840e04c66955af3eed0b5
7
- data.tar.gz: cb43747010d8c0aa4243a4d8d161270d54d4b2e19a75acb2dd9f446415157d70047bfa889a3e5ff61187abd7be7905019bf8e50abc88bb5cc7be36ab17e2727c
6
+ metadata.gz: 205587c667edec2a887cfc34bc1b718ce658d179d6574466567fc3f6dc0b0ba79325988b3613b7d4b9c434951bde976d06be9f638ae154b9f00578f16b7d5ac3
7
+ data.tar.gz: 3281aadd5d49ece99453e720e0cf254988dd96a9e8a2e1ae985b01bdd256d9b56a8c69d1d0d65e26ad592340587e38667c0d589d9ec94d3a402efd3d56258f97
@@ -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
@@ -3,28 +3,42 @@ module Sidekiq
3
3
  module Repeatable
4
4
  module ClassMethods
5
5
  def repeat(&block)
6
- @cronline = MiniIceCube::MainDsl.new.instance_eval(&block).to_s
6
+ @block = block
7
+ end
8
+
9
+ def cronline
10
+ return @cronline if @cronline
11
+ return if @block.nil?
12
+ @cronline = MiniIceCube::MainDsl.new.instance_eval(&@block).to_s
7
13
  @cronline = CronParser.new(@cronline)
14
+
8
15
  rescue ArgumentError
9
16
  fail "repeat '#{@cronline}' in class #{self.name} is not a valid cron line"
10
17
  end
11
18
 
12
19
  def reschedule
13
- return unless repeat_configured?
14
- return if already_scheduled?
20
+ # Only if repeat is configured.
21
+ return unless !!cronline
15
22
 
16
- ts = @cronline.next
17
- self.perform_at ts.to_f
18
- Sidekiq.logger.info "Scheduled #{self.name} for #{ts}."
19
- end
23
+ ts = cronline.next
24
+ args = [Time.now.to_f, ts.to_f].take(instance_method(:perform).arity)
25
+ nj = next_scheduled_job
20
26
 
21
- def repeat_configured?
22
- !!@cronline
27
+ if nj
28
+ if nj.at > ts
29
+ nj.item['args'] = args
30
+ nj.reschedule ts.to_f
31
+ Sidekiq.logger.info "Re-scheduled #{self.name} for #{ts}."
32
+ end
33
+ else
34
+ self.perform_at ts.to_f, *args
35
+ Sidekiq.logger.info "Scheduled #{self.name} for #{ts}."
36
+ end
23
37
  end
24
38
 
25
- def already_scheduled?
39
+ def next_scheduled_job
26
40
  @ss ||= Sidekiq::ScheduledSet.new
27
- @ss.any? { |job| job.klass == self.name }
41
+ @ss.find { |job| job.klass == self.name }
28
42
  end
29
43
  end
30
44
 
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Repeat
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-repeat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - FlavourSys Technology GmbH
7
+ - Projective Technology GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-12 00:00:00.000000000 Z
11
+ date: 2021-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3'
19
+ version: '6'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: '3'
29
+ version: '6'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: parse-cron
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +44,20 @@ dependencies:
38
44
  - - "~>"
39
45
  - !ruby/object:Gem::Version
40
46
  version: '0.1'
47
+ - !ruby/object:Gem::Dependency
48
+ name: redlock
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1'
41
61
  - !ruby/object:Gem::Dependency
42
62
  name: minitest
43
63
  requirement: !ruby/object:Gem::Requirement
@@ -54,32 +74,47 @@ dependencies:
54
74
  version: '3'
55
75
  - !ruby/object:Gem::Dependency
56
76
  name: rake
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 12.3.3
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 12.3.3
89
+ - !ruby/object:Gem::Dependency
90
+ name: redis-namespace
57
91
  requirement: !ruby/object:Gem::Requirement
58
92
  requirements:
59
93
  - - "~>"
60
94
  - !ruby/object:Gem::Version
61
- version: '10.4'
95
+ version: '1.3'
62
96
  type: :development
63
97
  prerelease: false
64
98
  version_requirements: !ruby/object:Gem::Requirement
65
99
  requirements:
66
100
  - - "~>"
67
101
  - !ruby/object:Gem::Version
68
- version: '10.4'
102
+ version: '1.3'
69
103
  description: This gem adds recurring jobs to Sidekiq. It is heavily inspired by the
70
104
  sidekiq-dejavu and sidetiq gems.
71
- email: technology@flavoursys.com
105
+ email: technology@projective.io
72
106
  executables: []
73
107
  extensions: []
74
108
  extra_rdoc_files: []
75
109
  files:
76
110
  - lib/sidekiq-repeat.rb
77
111
  - lib/sidekiq/repeat.rb
112
+ - lib/sidekiq/repeat/configuration.rb
78
113
  - lib/sidekiq/repeat/middleware.rb
79
114
  - lib/sidekiq/repeat/mini_ice_cube.rb
80
115
  - lib/sidekiq/repeat/repeatable.rb
81
116
  - lib/sidekiq/repeat/version.rb
82
- homepage: https://github.com/FlavourSys/sidekiq-repeat
117
+ homepage: https://github.com/projectivetech/sidekiq-repeat
83
118
  licenses:
84
119
  - MIT
85
120
  metadata: {}
@@ -98,8 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
133
  - !ruby/object:Gem::Version
99
134
  version: '0'
100
135
  requirements: []
101
- rubyforge_project:
102
- rubygems_version: 2.2.2
136
+ rubygems_version: 3.2.5
103
137
  signing_key:
104
138
  specification_version: 4
105
139
  summary: Repeat is a clockless recurring job system for Sidekiq.