Skip to content

Commit

Permalink
Support Rails 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
reidmorrison committed Nov 9, 2023
1 parent 096fbf6 commit e3d1bfe
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 11 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ jobs:
ruby: 2.7
- mongoid: 7.5
ruby: "3.0"
- mongoid: 7.5
ruby: jruby

- mongoid: 8.0
ruby: 3.1

- mongoid: 8.1
ruby: 3.1
Expand Down
10 changes: 9 additions & 1 deletion Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ appraise "mongoid_7.5" do
gem "sqlite3", "~> 1.4", platform: :ruby
end

appraise "mongoid_8.1" do
appraise "mongoid_8.0" do
gem "activerecord", "~> 7.0.0"
gem "activerecord-jdbcsqlite3-adapter", "~> 70.1", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "mongoid", "~> 8.0.0"
gem "sqlite3", "~> 1.4", platform: :ruby
end

appraise "mongoid_8.1" do
gem "activerecord", "~> 7.1.0"
gem "activerecord-jdbcsqlite3-adapter", "~> 70.1", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "mongoid", "~> 8.1.0"
gem "sqlite3", "~> 1.4", platform: :ruby
end
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ source "https://rubygems.org"

gemspec

gem "activerecord", "~> 7.0.0"
gem "activerecord", "~> 7.1.0"
gem "activerecord-jdbcsqlite3-adapter", "~> 70.1", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "mongoid", "~> 8.1.0"
gem "mongoid", "~> 8.0"
gem "sqlite3", "~> 1.4", platform: :ruby

gem "amazing_print"
Expand Down
27 changes: 27 additions & 0 deletions gemfiles/mongoid_8.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 7.0.0"
gem "activerecord-jdbcsqlite3-adapter", "~> 70.1", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "mongoid", "~> 8.0.0"
gem "sqlite3", "~> 1.4", platform: :ruby
gem "amazing_print"
gem "appraisal"
gem "rake"
gem "rubyzip", platform: :ruby
gem "bzip2-ffi"
gem "i18n", "1.8.7"

group :development do
gem "rubocop"
end

group :test do
gem "minitest"
gem "minitest-reporters"
gem "minitest-stub_any_instance"
end

gemspec path: "../"
2 changes: 1 addition & 1 deletion gemfiles/mongoid_8.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

gem "activerecord", "~> 7.0.0"
gem "activerecord", "~> 7.1.0"
gem "activerecord-jdbcsqlite3-adapter", "~> 70.1", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "mongoid", "~> 8.1.0"
Expand Down
4 changes: 2 additions & 2 deletions lib/rocket_job/batch/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def rocket_job_batch_complete?(worker_name)
result = self.class.with(write: {w: 1}) do |query|
query.
where(id: id, state: :running, sub_state: :processing).
update("$set" => {sub_state: :after, worker_name: worker_name})
update("$set" => {sub_state: "after", worker_name: worker_name})
end

# Reload to pull in any counters or other data that was modified.
Expand All @@ -251,7 +251,7 @@ def rocket_job_batch_fail!(worker_name)
result = self.class.with(write: {w: 1}) do |query|
query.
where(id: id, state: :running, sub_state: :processing).
update({"$set" => {state: :failed, worker_name: worker_name}})
update({"$set" => {state: "failed", worker_name: worker_name}})
end
fail_job = false unless result.modified_count.positive?
end
Expand Down
9 changes: 8 additions & 1 deletion lib/rocket_job/jobs/upload_file_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ def upload_file(job)
if job.respond_to?(:upload)
# Return the database connection for this thread back to the connection pool
# in case the upload takes a long time and the database connection expires.
ActiveRecord::Base.clear_active_connections! if defined?(ActiveRecord::Base)
if defined?(ActiveRecord::Base)
if ActiveRecord::Base.respond_to?(:connection_handler)
# Rails 7
ActiveRecord::Base.connection_handler.clear_active_connections!
else
ActiveRecord::Base.connection_pool.release_connection
end
end

if original_file_name
job.upload(upload_file_name, file_name: original_file_name)
Expand Down
3 changes: 3 additions & 0 deletions lib/rocket_job/rocket_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ def self.rails!
@rails = true
end
end

# Slice is a reserved word in Rails 7, but already being used in RocketJob long before that.
Mongoid.destructive_fields.delete(:slice) if Mongoid.respond_to?(:destructive_fields)
4 changes: 2 additions & 2 deletions lib/rocket_job/sliced/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ def each_failed_record
def requeue_failed
failed.update_all(
"$unset" => {worker_name: nil, started_at: nil},
"$set" => {state: :queued}
"$set" => {state: "queued"}
)
end

# Requeue all running slices for a server or worker that is no longer available
def requeue_running(worker_name)
running.where(worker_name: /\A#{worker_name}/).update_all(
"$unset" => {worker_name: nil, started_at: nil},
"$set" => {state: :queued}
"$set" => {state: "queued"}
)
end

Expand Down

0 comments on commit e3d1bfe

Please sign in to comment.