schked 1.2.0 → 1.3.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
2
  SHA256:
3
- metadata.gz: b3a998f39285529b65c224e884f0ddf35c60cf14c27aadf76898424286d1b339
4
- data.tar.gz: 2d9b8d5af4b547c9829030d74b66252cc22326db47073faffa230c992ab4427a
3
+ metadata.gz: 3cb8172851d135726e8cf5ae569e378c4855de6b78466fc19786a81fcd08045a
4
+ data.tar.gz: 0d448a52410312f3b0c6132059bc43a6f4f147b242ad4f7bfb1a47742df07990
5
5
  SHA512:
6
- metadata.gz: 1f7148205a8ca6f3f5ebfa971187544e447bb753c3d1214fe84dacd705e6c1046db3e523f7402a05a7c35325205feeefcbd47428f4a42ff036d8ac4dd8dfff2a
7
- data.tar.gz: 5c3e8b3af739d7359cd9d5114171eabe7fef0b6fc3f02fcec6353ada371958e372ee8e46c3ae6939757a02a7c43497dbf642c33f1b01a6ff5ec6069c11b36130
6
+ metadata.gz: 89be3ba061cc48c06024ca0f1697dc74d2dd383e5e1c73dbe14ffeb3d781862004341d45643db09081a7997c753912e3fb7e3af1d8fb778a9a768582302af3ab
7
+ data.tar.gz: 430bdb484f6962a1e41efeef2b47112614f98356cfe6d4e68eabb0f871c566bbca368e0f19e438383c680184740c32087f50757bdf31f0a7440506ae97c71287
data/README.md CHANGED
@@ -79,7 +79,7 @@ When you deploy your schedule to production, you want to start new instance befo
79
79
  You can configure Redis client as the following:
80
80
 
81
81
  ```ruby
82
- Schked.config.redis_servers = ["redis://127.0.0.1:7777", "redis://127.0.0.1:7778", "redis://127.0.0.1:7779"]
82
+ Schked.config.redis = {url: ENV.fetch("REDIS_URL") }
83
83
  ```
84
84
 
85
85
  ### Callbacks
data/lib/schked/config.rb CHANGED
@@ -6,7 +6,7 @@ module Schked
6
6
  class Config
7
7
  attr_writer :logger,
8
8
  :do_not_load_root_schedule,
9
- :redis_servers,
9
+ :redis,
10
10
  :standalone
11
11
 
12
12
  def paths
@@ -48,8 +48,23 @@ module Schked
48
48
  end
49
49
  end
50
50
 
51
- def redis_servers
52
- @redis_servers ||= [ENV.fetch("REDIS_URL", "redis://127.0.0.1:6379")]
51
+ def redis
52
+ @redis ||= {url: ENV.fetch("REDIS_URL", "redis://127.0.0.1:6379")}
53
+ end
54
+
55
+ def redis_servers=(val)
56
+ val = val.first
57
+
58
+ if val.is_a?(String)
59
+ self.redis = {url: val}
60
+ elsif val.respond_to?(:_client)
61
+ conf = val._client.config
62
+ self.redis = {url: conf.server_url, username: conf.username, password: conf.password}
63
+ else
64
+ raise ArgumentError, "Schked `redis_servers=` config option is deprecated. Please use `redis=` with a Hash"
65
+ end
66
+
67
+ warn "🔥 Schked `redis_servers=` config option is deprecated. Please use `redis=` with a Hash. Called from #{caller(1..1).first}"
53
68
  end
54
69
 
55
70
  def standalone?
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "redis-client"
4
+
5
+ module Schked
6
+ module RedisClientFactory
7
+ def self.build(options)
8
+ unless options.key?(:reconnect_attempts)
9
+ options[:reconnect_attempts] = 3
10
+ end
11
+
12
+ if options.key?(:sentinels)
13
+ if (url = options.delete(:url))
14
+ uri = URI.parse(url)
15
+ if !options.key?(:name) && uri.host
16
+ options[:name] = uri.host
17
+ end
18
+
19
+ if !options.key?(:password) && uri.password && !uri.password.empty?
20
+ options[:password] = uri.password
21
+ end
22
+
23
+ if !options.key?(:username) && uri.user && !uri.user.empty?
24
+ options[:username] = uri.user
25
+ end
26
+ end
27
+
28
+ RedisClient.sentinel(**options).new_client
29
+ else
30
+ RedisClient.config(**options).new_client
31
+ end
32
+ end
33
+ end
34
+ end
@@ -10,8 +10,8 @@ module Schked
10
10
  LOCK_KEY = "schked:redis_locker"
11
11
  LOCK_TTL = 60_000 # ms
12
12
 
13
- def initialize(redis_servers, lock_ttl: LOCK_TTL, logger: Logger.new($stdout))
14
- @lock_manager = Redlock::Client.new(redis_servers, retry_count: 0)
13
+ def initialize(redis_conf, lock_ttl: LOCK_TTL, logger: Logger.new($stdout))
14
+ @lock_manager = Redlock::Client.new([redis_client(redis_conf)], retry_count: 0)
15
15
  @lock_ttl = lock_ttl
16
16
  @logger = logger
17
17
  end
@@ -49,6 +49,14 @@ module Schked
49
49
 
50
50
  private
51
51
 
52
+ def redis_client(redis_conf)
53
+ if Gem::Version.new(Redlock::VERSION) >= Gem::Version.new("2.0.0")
54
+ ConnectionPool::Wrapper.new { RedisClientFactory.build(redis_conf) }
55
+ else
56
+ ConnectionPool::Wrapper.new { Redis.new(**redis_conf) }
57
+ end
58
+ end
59
+
52
60
  def try_lock
53
61
  @lock_id = lock_manager.lock(LOCK_KEY, lock_ttl)
54
62
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Schked
4
- VERSION = "1.2.0"
4
+ VERSION = "1.3.0"
5
5
  end
data/lib/schked/worker.rb CHANGED
@@ -7,7 +7,8 @@ module Schked
7
7
  def initialize(config:)
8
8
  @config = config
9
9
 
10
- @locker = RedisLocker.new(config.redis_servers, lock_ttl: 40_000, logger: config.logger) unless config.standalone?
10
+ @locker = RedisLocker.new(config.redis, lock_ttl: 40_000, logger: config.logger) unless config.standalone?
11
+
11
12
  @scheduler = Rufus::Scheduler.new(trigger_lock: locker)
12
13
 
13
14
  watch_signals
data/lib/schked.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "connection_pool"
3
4
  require "redlock"
4
5
 
5
6
  require "schked/version"
6
7
  require "schked/config"
7
8
  require "schked/worker"
8
9
  require "schked/redis_locker"
10
+ require "schked/redis_client_factory"
9
11
  require "schked/railtie" if defined?(Rails)
10
12
 
11
13
  module Schked
metadata CHANGED
@@ -1,29 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schked
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Misha Merkushin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-09 00:00:00.000000000 Z
11
+ date: 2023-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: connection_pool
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: redlock
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - ">="
31
+ - - ">"
18
32
  - !ruby/object:Gem::Version
19
- version: '0'
33
+ version: '1.0'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '3.0'
20
37
  type: :runtime
21
38
  prerelease: false
22
39
  version_requirements: !ruby/object:Gem::Requirement
23
40
  requirements:
24
- - - ">="
41
+ - - ">"
25
42
  - !ruby/object:Gem::Version
26
- version: '0'
43
+ version: '1.0'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: rufus-scheduler
29
49
  requirement: !ruby/object:Gem::Requirement
@@ -94,20 +114,6 @@ dependencies:
94
114
  - - "~>"
95
115
  - !ruby/object:Gem::Version
96
116
  version: '1.3'
97
- - !ruby/object:Gem::Dependency
98
- name: pry-byebug
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '3.9'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '3.9'
111
117
  - !ruby/object:Gem::Dependency
112
118
  name: rake
113
119
  requirement: !ruby/object:Gem::Requirement
@@ -123,19 +129,19 @@ dependencies:
123
129
  - !ruby/object:Gem::Version
124
130
  version: '13.0'
125
131
  - !ruby/object:Gem::Dependency
126
- name: redis
132
+ name: redis-client
127
133
  requirement: !ruby/object:Gem::Requirement
128
134
  requirements:
129
135
  - - "~>"
130
136
  - !ruby/object:Gem::Version
131
- version: '5.0'
137
+ version: '0.10'
132
138
  type: :development
133
139
  prerelease: false
134
140
  version_requirements: !ruby/object:Gem::Requirement
135
141
  requirements:
136
142
  - - "~>"
137
143
  - !ruby/object:Gem::Version
138
- version: '5.0'
144
+ version: '0.10'
139
145
  - !ruby/object:Gem::Dependency
140
146
  name: rspec
141
147
  requirement: !ruby/object:Gem::Requirement
@@ -179,6 +185,7 @@ files:
179
185
  - lib/schked/cli.rb
180
186
  - lib/schked/config.rb
181
187
  - lib/schked/railtie.rb
188
+ - lib/schked/redis_client_factory.rb
182
189
  - lib/schked/redis_locker.rb
183
190
  - lib/schked/version.rb
184
191
  - lib/schked/worker.rb
@@ -193,9 +200,9 @@ require_paths:
193
200
  - lib
194
201
  required_ruby_version: !ruby/object:Gem::Requirement
195
202
  requirements:
196
- - - ">"
203
+ - - ">="
197
204
  - !ruby/object:Gem::Version
198
- version: '2.5'
205
+ version: '2.7'
199
206
  required_rubygems_version: !ruby/object:Gem::Requirement
200
207
  requirements:
201
208
  - - ">="