Skip to content

Commit

Permalink
Actually change the smaller_number_is_higher_priority for v4 (#1402)
Browse files Browse the repository at this point in the history
  • Loading branch information
Earlopain committed Jul 8, 2024
1 parent c879d5d commit e0acb42
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 0 additions & 3 deletions demo/config/initializers/good_job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
Rails.application.configure do
# TODO: Remove on GoodJob 4.0 release
config.good_job.smaller_number_is_higher_priority = true

config.good_job.cron = {
example: {
cron: '*/5 * * * * *', # every 5 seconds
Expand Down
6 changes: 5 additions & 1 deletion lib/good_job/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class Configuration
DEFAULT_DASHBOARD_LIVE_POLL_ENABLED = true
# Default enqueue_after_transaction_commit
DEFAULT_ENQUEUE_AFTER_TRANSACTION_COMMIT = false
# Default smaller_number_is_higher_priority
DEFAULT_SMALLER_NUMBER_IS_HIGHER_PRIORITY = true

def self.validate_execution_mode(execution_mode)
raise ArgumentError, "GoodJob execution mode must be one of #{EXECUTION_MODES.join(', ')}. It was '#{execution_mode}' which is not valid." unless execution_mode.in?(EXECUTION_MODES)
Expand Down Expand Up @@ -378,7 +380,9 @@ def enable_listen_notify
end

def smaller_number_is_higher_priority
rails_config[:smaller_number_is_higher_priority]
return rails_config[:smaller_number_is_higher_priority] unless rails_config[:smaller_number_is_higher_priority].nil?

DEFAULT_SMALLER_NUMBER_IS_HIGHER_PRIORITY
end

def dashboard_default_locale
Expand Down
6 changes: 3 additions & 3 deletions spec/app/models/good_job/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -579,14 +579,14 @@ def job_params
expect(described_class.priority_ordered.pluck(:priority)).to eq([-50, 50])
end

it 'smaller_number_is_higher_priority=false orders with smaller priority being LOWER priority' do
it 'smaller_number_is_higher_priority=false orders with smaller number being LOWER priority' do
allow(Rails.application.config).to receive(:good_job).and_return({ smaller_number_is_higher_priority: false })
expect(described_class.priority_ordered.pluck(:priority)).to eq([50, -50])
end

it 'smaller_number_is_higher_priority=false orders with lower priority being LOWER priority' do
it 'smaller_number_is_higher_priority=nil orders with smaller number being HIGHER priority' do
allow(Rails.application.config).to receive(:good_job).and_return({})
expect(described_class.priority_ordered.pluck(:priority)).to eq([50, -50])
expect(described_class.priority_ordered.pluck(:priority)).to eq([-50, 50])
end
end

Expand Down

0 comments on commit e0acb42

Please sign in to comment.