sidekiq-cron 1.5.1 → 1.6.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: 2d138bcaa8a86a88e84e5cd8b5b9188e68217e268a466aef03f2b5dd30a7226d
4
- data.tar.gz: 8cae5daa6693161b48b71b40607a0c8182764a82ffc3efd5eb8fd7bd0df65da7
3
+ metadata.gz: ccf886f1cd7a1369e8a3dc9a9b9bff96c0742e22e751d9ae61e66f9fa376f873
4
+ data.tar.gz: 7ad6cd7f4637e0264cdfe529a960891275cd37c03e8bb3eb5e856bfadaa879a1
5
5
  SHA512:
6
- metadata.gz: 0dd9f32211d51bbd71fadbd36b30970193fc725408207fe255ff58f88b56dc484815a0f52c788acebbcc6230665cf7c02ccdbd4f7425dd4d9414cd8dd098dbf7
7
- data.tar.gz: 73e8040c64d5de227d0077a1d95081d47140ec0481706b16c00e830f421ce8952f0fb48a991f71033c65a115dc0f29f06e2a6c56aae38565ed5dae6bfcaea14d
6
+ metadata.gz: 90d285a52788e04f6eb253f9f1b215e82a2ab68dc225eb3a4f4f6e2424cfbc190e629a9fa36238b03510cbcc1e2868d9dbf66efd8adbcd68d0aa48a5362e6ba2
7
+ data.tar.gz: cb48a228304927385f5ea69da2d233fb338efe85875c1e1bd14c3d8b52bf0cf286c307d0c841b04fc98b71453167cb4e932b7f67a15f27faadef580154be4a1f
@@ -2,6 +2,11 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## 1.6.0
6
+
7
+ - Adds support for auto-loading the config/schedule.yml file (https://github.com/ondrejbartas/sidekiq-cron/pull/337)
8
+ - Fix Sidekiq.options deprecation warning (https://github.com/ondrejbartas/sidekiq-cron/pull/338)
9
+
5
10
  ## 1.5.1
6
11
 
7
12
  - Fixes an issue that prevented the gem to work in previous Sidekiq versions (https://github.com/ondrejbartas/sidekiq-cron/pull/335)
data/README.md CHANGED
@@ -27,7 +27,7 @@ Please be aware that Sidekiq-Cron < 1.0 was relying on rufus-scheduler < 3.5. Us
27
27
 
28
28
  ## Changelog
29
29
 
30
- Before upgrading to a new version, please read our [Changelog](Changes.md).
30
+ Before upgrading to a new version, please read our [Changelog](CHANGELOG.md).
31
31
 
32
32
  ## Installation
33
33
 
@@ -94,7 +94,7 @@ For example: `"*/30 * * * * *"` would schedule a job to run every 30 seconds.
94
94
  Note that if you plan to schedule jobs with second precision you may need to override the default schedule poll interval so it is lower than the interval of your jobs:
95
95
 
96
96
  ```ruby
97
- Sidekiq.options[:average_scheduled_poll_interval] = 10
97
+ Sidekiq[:average_scheduled_poll_interval] = 10
98
98
  ```
99
99
 
100
100
  The default value at time of writing is 30 seconds. See [under the hood](#under-the-hood) for more details.
@@ -227,21 +227,19 @@ second_job:
227
227
  hard: "stuff"
228
228
  ```
229
229
 
230
- ```ruby
231
- # config/initializers/sidekiq.rb
232
- schedule_file = "config/schedule.yml"
233
-
234
- if File.exist?(schedule_file) && Sidekiq.server?
235
- Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
236
- end
237
- ```
230
+ There are multiple ways to load the jobs from a YAML file
238
231
 
239
- From version 3.x it is better not to use separate initializer of schedule instead add `config.on(:startup)` to your Sidekiq configuration:
232
+ 1. The gem will automatically load the jobs mentioned in `config/schedule.yml` file.
233
+ 2. When you want to load jobs from a different filename, mention the filename in sidekiq configuration,
234
+ i.e. `cron_schedule_file: "config/users_schedule.yml"`
235
+ 3. Load the file manually as follows
240
236
 
241
237
  ```ruby
238
+ # config/initializers/sidekiq.rb
239
+
242
240
  Sidekiq.configure_server do |config|
243
241
  config.on(:startup) do
244
- schedule_file = "config/schedule.yml"
242
+ schedule_file = "config/users_schedule.yml"
245
243
 
246
244
  if File.exist?(schedule_file)
247
245
  Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
@@ -316,30 +314,6 @@ With this, you will get:
316
314
 
317
315
  ![Web UI](examples/web-cron-ui.png)
318
316
 
319
- ### Forking Processes or problem with `NotImplementedError`
320
-
321
- If you're using a forking web server like Unicorn you may run into an issue where the Redis connection is used
322
- before the process forks, causing the following exception to occur:
323
-
324
- ```
325
- Redis::InheritedError: Tried to use a connection from a child process without reconnecting. You need to reconnect to Redis after forking.
326
- ```
327
-
328
- To avoid this, wrap your job creation in the call to `Sidekiq.configure_server`:
329
-
330
- ```ruby
331
- Sidekiq.configure_server do |config|
332
- config.on(:startup) do
333
- schedule_file = "config/schedule.yml"
334
-
335
- if File.exist?(schedule_file)
336
- Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
337
- end
338
- end
339
- end
340
- ```
341
-
342
- **NOTE** This API is only available in Sidekiq 3.x.
343
317
 
344
318
  ## Under the hood
345
319
 
@@ -350,7 +324,7 @@ Sidekiq-Cron adds itself into this start procedure and starts another thread wit
350
324
  Sidekiq-Cron is checking jobs to be enqueued every 30s by default, you can change it by setting:
351
325
 
352
326
  ```ruby
353
- Sidekiq.options[:average_scheduled_poll_interval] = 10
327
+ Sidekiq[:average_scheduled_poll_interval] = 10
354
328
  ```
355
329
 
356
330
  Sidekiq-Cron is safe to use with multiple Sidekiq processes or nodes. It uses a Redis sorted set to determine that only the first process who asks can enqueue scheduled jobs into the queue.
@@ -478,7 +478,8 @@ module Sidekiq
478
478
  jid: jid,
479
479
  enqueued: @last_enqueue_time
480
480
  }
481
- @history_size ||= (Sidekiq.options[:cron_history_size] || 10).to_i - 1
481
+ cron_history_size = Sidekiq.respond_to?(:[]) ? Sidekiq[:cron_history_size] : Sidekiq.options[:cron_history_size]
482
+ @history_size ||= (cron_history_size || 10).to_i - 1
482
483
  Sidekiq.redis do |conn|
483
484
  conn.lpush jid_history_key,
484
485
  Sidekiq.dump_json(jid_history)
@@ -0,0 +1,14 @@
1
+ require "sidekiq"
2
+ require "sidekiq/cron/job"
3
+
4
+ if Sidekiq.server?
5
+ Sidekiq.configure_server do |config|
6
+ schedule_file = config.options[:cron_schedule_file] || "config/schedule.yml"
7
+
8
+ if File.exist?(schedule_file)
9
+ config.on(:startup) do
10
+ Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Cron
5
- VERSION = "1.5.1"
5
+ VERSION = "1.6.0"
6
6
  end
7
7
  end
data/lib/sidekiq/cron.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "sidekiq/cron/job"
2
2
  require "sidekiq/cron/poller"
3
3
  require "sidekiq/cron/launcher"
4
+ require "sidekiq/cron/schedule_loader"
4
5
 
5
6
  module Sidekiq
6
7
  module Cron
data/sidekiq-cron.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  "README.md"
17
17
  ]
18
18
  s.files = Dir.glob('lib/**/*') + Dir.glob('test/**/*') + [
19
- "Changes.md",
19
+ "CHANGELOG.md",
20
20
  "Gemfile",
21
21
  "LICENSE.txt",
22
22
  "Rakefile",
@@ -1030,6 +1030,16 @@ describe "Cron Job" do
1030
1030
  assert_equal Sidekiq::Cron::Job.all.size, 2, "Should have 2 jobs after load"
1031
1031
  end
1032
1032
 
1033
+ it "duplicate jobs are not loaded" do
1034
+ out = Sidekiq::Cron::Job.load_from_hash @jobs_hash
1035
+ assert_equal out.size, 0, "should have no errors"
1036
+ assert_equal Sidekiq::Cron::Job.all.size, 2, "Should have 2 jobs after load"
1037
+
1038
+ out_2 = Sidekiq::Cron::Job.load_from_hash @jobs_hash
1039
+ assert_equal out_2.size, 0, "should have no errors"
1040
+ assert_equal Sidekiq::Cron::Job.all.size, 2, "Should have 2 jobs after loading again"
1041
+ end
1042
+
1033
1043
  it "return errors on loaded jobs" do
1034
1044
  assert_equal Sidekiq::Cron::Job.all.size, 0, "Should have 0 jobs before load"
1035
1045
  #set something bag to hash
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-cron
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondrej Bartas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-10 00:00:00.000000000 Z
11
+ date: 2022-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fugit
@@ -144,7 +144,7 @@ extra_rdoc_files:
144
144
  - LICENSE.txt
145
145
  - README.md
146
146
  files:
147
- - Changes.md
147
+ - CHANGELOG.md
148
148
  - Gemfile
149
149
  - LICENSE.txt
150
150
  - README.md
@@ -160,6 +160,7 @@ files:
160
160
  - lib/sidekiq/cron/locales/ru.yml
161
161
  - lib/sidekiq/cron/locales/zh-CN.yml
162
162
  - lib/sidekiq/cron/poller.rb
163
+ - lib/sidekiq/cron/schedule_loader.rb
163
164
  - lib/sidekiq/cron/support.rb
164
165
  - lib/sidekiq/cron/version.rb
165
166
  - lib/sidekiq/cron/views/cron.erb
@@ -191,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
192
  - !ruby/object:Gem::Version
192
193
  version: '0'
193
194
  requirements: []
194
- rubygems_version: 3.1.6
195
+ rubygems_version: 3.1.4
195
196
  signing_key:
196
197
  specification_version: 4
197
198
  summary: Sidekiq-Cron helps to add repeated scheduled jobs