Skip to content

Commit

Permalink
Update BarbequeAdapter for Rails 7.2 compatibility (#18)
Browse files Browse the repository at this point in the history
* Update BarbequeAdapter for Rails 7.2 compatibility

In Rails 7.2, a new class called ActiveJob::QueueAdapter::AbstractAdapter was added. It looks like custom adapters should basically inherit from this class.
Considering the support period for Rails, it would be better to stop supporting versions less than Rails 7.2 and make codes simpler.

- Update gemspec to require Rails 7.2 (ActiveJob) and above
- Refactor BarbequeAdapter to inherit from ActiveJob::AbstractAdapter

* Rails 7.2 requires Ruby 3.1 or higher
  • Loading branch information
hfm authored Jan 16, 2025
1 parent bf54842 commit 1beffa4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 32 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ jobs:
fail-fast: false
matrix:
ruby:
- '2.6'
- '2.7'
- '3.0'
- '3.1'
- '3.2'
- '3.3'
Expand Down
4 changes: 3 additions & 1 deletion barbeque_client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_dependency 'garage_client'
spec.add_dependency 'activejob', '>= 7.2'
spec.add_dependency 'railties', '>= 7.2'
spec.add_development_dependency 'bundler'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'rails', '~> 6.1.4'
spec.add_development_dependency 'rails', '>= 7.2'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec-rails'
end
42 changes: 15 additions & 27 deletions lib/active_job/queue_adapters/barbeque_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,24 @@
module ActiveJob
module QueueAdapters
class BarbequeAdapter
# Interface for ActiveJob 5.0
class BarbequeAdapter < ActiveJob::QueueAdapters::AbstractAdapter
def enqueue(job)
BarbequeAdapter.enqueue(job)
execution = BarbequeClient.enqueue(
job: job.class.to_s,
message: ActiveJob::Arguments.serialize(job.arguments),
queue: job.queue_name,
)
job.job_id = execution.message_id
end

def enqueue_at(job, timestamp)
BarbequeAdapter.enqueue_at(job, timestamp)
end

class << self
# Interface for ActiveJob 4.2
def enqueue(job)
execution = BarbequeClient.enqueue(
job: job.class.to_s,
message: ActiveJob::Arguments.serialize(job.arguments),
queue: job.queue_name,
)
job.job_id = execution.message_id
end

def enqueue_at(job, timestamp)
delay_seconds = (timestamp - Time.now.to_f).round
execution = BarbequeClient.enqueue(
job: job.class.to_s,
message: ActiveJob::Arguments.serialize(job.arguments),
queue: job.queue_name,
delay_seconds: delay_seconds,
)
job.job_id = execution.message_id
end
delay_seconds = (timestamp - Time.now.to_f).round
execution = BarbequeClient.enqueue(
job: job.class.to_s,
message: ActiveJob::Arguments.serialize(job.arguments),
queue: job.queue_name,
delay_seconds: delay_seconds,
)
job.job_id = execution.message_id
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/barbeque_client/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module BarbequeClient
VERSION = '0.10.2'
VERSION = '0.11.0'
end

0 comments on commit 1beffa4

Please sign in to comment.