Skip to content

Commit

Permalink
Add versioned default queue support for 1.0 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
hlascelles committed Jul 20, 2019
1 parent 813811e commit 0378962
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased

- Add facade to handle Que.execute differences between versions [#101](https://github.com/hlascelles/que-scheduler/pull/101)
- Add facade to handle default queue differences between versions [#103](https://github.com/hlascelles/que-scheduler/pull/103)

## 3.2.4 (2019-07-14)

Expand Down
3 changes: 3 additions & 0 deletions lib/que/scheduler/config.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'que'
require_relative 'version_support'

module Que
module Scheduler
Expand All @@ -14,11 +15,13 @@ def self.configure
class Configuration
attr_accessor :schedule_location
attr_accessor :transaction_adapter
attr_accessor :que_scheduler_queue
end
end
end

Que::Scheduler.configure do |config|
config.schedule_location = ENV.fetch('QUE_SCHEDULER_CONFIG_LOCATION', 'config/que_schedule.yml')
config.transaction_adapter = ::Que.method(:transaction)
config.que_scheduler_queue = Que::Scheduler::VersionSupport.default_scheduler_queue
end
1 change: 1 addition & 0 deletions lib/que/scheduler/scheduler_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def enqueue_self_again(scheduler_job_args, last_full_execution, job_dictionary,
# And rerun...
next_run_at = scheduler_job_args.as_time.beginning_of_minute + SCHEDULER_FREQUENCY
enqueued_job = SchedulerJob.enqueue(
queue: Que::Scheduler.configuration.que_scheduler_queue,
last_run_time: last_full_execution.iso8601,
job_dictionary: job_dictionary,
run_at: next_run_at
Expand Down
4 changes: 4 additions & 0 deletions lib/que/scheduler/version_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def execute(str, args = [])
normalise_array_of_hashes(Que.execute(str, args))
end

def default_scheduler_queue
''
end

def normalise_array_of_hashes(array)
array.map { |row| row.transform_keys(&:to_sym) }
end
Expand Down
2 changes: 1 addition & 1 deletion spec/que/scheduler/audit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{
scheduler_job_id: 1234,
job_class: 'HalfHourlyTestJob',
queue: '',
queue: Que::Scheduler.configuration.que_scheduler_queue,
priority: 80,
args: '[]',
job_id: enqueued_jobs[1].attrs.fetch('job_id'),
Expand Down
2 changes: 1 addition & 1 deletion spec/que/scheduler/scheduler_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def expect_one_itself_job

def expect_itself_enqueued
hash = expect_one_itself_job
expect(hash.fetch(:queue)).to eq('')
expect(hash.fetch(:queue)).to eq(Que::Scheduler.configuration.que_scheduler_queue)
expect(hash.fetch(:priority)).to eq(0)
expect(hash.fetch(:error_count)).to eq(0)
expect(hash.fetch(:job_class)).to eq('Que::Scheduler::SchedulerJob')
Expand Down
1 change: 1 addition & 0 deletions spec/support/db_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def setup_db
reconnect: true,
}
ActiveRecord::Base.establish_connection(db_config.merge(database: 'postgres'))

conn = ActiveRecord::Base.connection
if conn.execute("SELECT 1 from pg_database WHERE datname='#{testing_db}';").count > 0
conn.execute("DROP DATABASE #{testing_db}")
Expand Down

0 comments on commit 0378962

Please sign in to comment.