Skip to content

Commit

Permalink
Rearrange options + minor tweaks in tests and docs (sidekiq-cron#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
markets authored Oct 20, 2024
1 parent 229d9b0 commit b0049b1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 32 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ All configuration options:

```ruby
Sidekiq::Cron.configure do |config|
config.cron_poll_interval = 10
config.cron_schedule_file = 'config/my_schedule.yml'
config.default_namespace = 'statistics'
config.natural_cron_parsing_mode = :single
config.reschedule_grace_period = 100
config.cron_history_size = 50
config.cron_poll_interval = 10 # Default is 30
config.cron_schedule_file = 'config/my_schedule.yml' # Default is 'config/schedule.yml'
config.cron_history_size = 20 # Default is 10
config.default_namespace = 'statistics' # Default is 'default'
config.natural_cron_parsing_mode = :strict # Default is :single
config.reschedule_grace_period = 300 # Default is 60
end
```

If you are using Rails, add them inside an initializer (`config/initializers/sidekiq-cron.rb`).
If you are using Rails, you should add the above block inside an initializer (`config/initializers/sidekiq-cron.rb`).

### Time, cron and Sidekiq-Cron

Expand Down
32 changes: 16 additions & 16 deletions lib/sidekiq/cron.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ def self.reset!
end

class Configuration
# The interval, in seconds, at which to poll for scheduled cron jobs.
# This determines how frequently the scheduler checks for jobs to enqueue.
attr_accessor :cron_poll_interval

# The path to a YAML file containing multiple cron job schedules.
attr_accessor :cron_schedule_file

# The maximum number of recent cron job execution histories to retain.
# This value controls how many past job executions are stored.
attr_accessor :cron_history_size

# The default namespace is used when no namespace is specified.
attr_accessor :default_namespace

Expand All @@ -26,29 +37,18 @@ class Configuration
# The poller will not enqueue jobs that are late by more than this amount of seconds.
# Defaults to 60 seconds.
#
# This is useful when sidekiq (and sidekiq-cron) is not used in zero downtime deployments and
# when the deployment is done and sidekiq-cron starts to catch up, it will consider older
# This is useful when Sidekiq (and Sidekiq-Cron) is not used in zero downtime deployments and
# when the deployment is done and Sidekiq-Cron starts to catch up, it will consider older
# jobs that missed their schedules during the deployment. E.g., jobs that run once a day.
attr_accessor :reschedule_grace_period

# The maximum number of recent cron job execution histories to retain.
# This value controls how many past job executions are stored.
attr_accessor :cron_history_size

# The interval, in seconds, at which to poll for scheduled cron jobs.
# This determines how frequently the scheduler checks for jobs to enqueue.
attr_accessor :cron_poll_interval

# The path to a YAML file containing multiple cron job schedules.
attr_accessor :cron_schedule_file

def initialize
@cron_poll_interval = 30
@cron_schedule_file = 'config/schedule.yml'
@cron_history_size = 10
@default_namespace = 'default'
@natural_cron_parsing_mode = :single
@reschedule_grace_period = 60
@cron_history_size = 10
@cron_poll_interval = 30
@cron_schedule_file = 'config/schedule.yml'
end

def natural_cron_parsing_mode=(mode)
Expand Down
5 changes: 1 addition & 4 deletions test/integration/performance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
MAX_SECONDS = 40

before do
# Clear all previous saved data from Redis.
Sidekiq.redis do |conn|
conn.flushdb
end
Sidekiq.redis(&:flushdb)

args = {
queue: "default",
Expand Down
4 changes: 2 additions & 2 deletions test/unit/launcher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

it 'initializes poller with default poll interval when not configured' do
Sidekiq::Cron::Poller.expects(:new).with do |options|
assert_equal Sidekiq::Cron.configuration.cron_poll_interval, options[:cron_poll_interval]
assert_equal 30, options[:cron_poll_interval]
end

Sidekiq::Launcher.new(Sidekiq::Options.config)
end

it 'initializes poller with the configured poll interval' do
Sidekiq::Cron::Poller.expects(:new).with do |options|
assert_equal Sidekiq::Cron.configuration.cron_poll_interval, options[:cron_poll_interval]
assert_equal 99, options[:cron_poll_interval]
end

Sidekiq::Cron.configuration.cron_poll_interval = 99
Expand Down
2 changes: 0 additions & 2 deletions test/unit/poller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require './test/test_helper'

#
# Prevents Sidekiq::Scheduler to run the safe_thread helper method
module Sidekiq
module Scheduled
Expand All @@ -13,7 +12,6 @@ def start; end
end

describe 'Cron Poller' do
# Clear all previous saved data from Redis.
before do
Sidekiq::Cron.reset!
Sidekiq.redis(&:flushdb)
Expand Down
3 changes: 2 additions & 1 deletion test/unit/web_extension_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def app
before do
env 'rack.session', { csrf: TOKEN }
env 'HTTP_X_CSRF_TOKEN', TOKEN
Sidekiq.redis { |c| c.flushdb }

Sidekiq.redis(&:flushdb)
end

let(:job_name) { "TestNameOfCronJob" }
Expand Down

0 comments on commit b0049b1

Please sign in to comment.