diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80e7d89..e603b59 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/Appraisals b/Appraisals index dc6ea04..1720c80 100644 --- a/Appraisals +++ b/Appraisals @@ -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 diff --git a/Gemfile b/Gemfile index f4a5d36..93f0da2 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/gemfiles/mongoid_8.0.gemfile b/gemfiles/mongoid_8.0.gemfile new file mode 100644 index 0000000..38ff7d5 --- /dev/null +++ b/gemfiles/mongoid_8.0.gemfile @@ -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: "../" diff --git a/gemfiles/mongoid_8.1.gemfile b/gemfiles/mongoid_8.1.gemfile index 909c007..d8d2836 100644 --- a/gemfiles/mongoid_8.1.gemfile +++ b/gemfiles/mongoid_8.1.gemfile @@ -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" diff --git a/lib/rocket_job/batch/worker.rb b/lib/rocket_job/batch/worker.rb index 121b946..c7b684c 100644 --- a/lib/rocket_job/batch/worker.rb +++ b/lib/rocket_job/batch/worker.rb @@ -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. @@ -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 diff --git a/lib/rocket_job/jobs/upload_file_job.rb b/lib/rocket_job/jobs/upload_file_job.rb index e804acf..b8668e9 100644 --- a/lib/rocket_job/jobs/upload_file_job.rb +++ b/lib/rocket_job/jobs/upload_file_job.rb @@ -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) diff --git a/lib/rocket_job/rocket_job.rb b/lib/rocket_job/rocket_job.rb index 2573c75..512ab12 100644 --- a/lib/rocket_job/rocket_job.rb +++ b/lib/rocket_job/rocket_job.rb @@ -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) diff --git a/lib/rocket_job/sliced/input.rb b/lib/rocket_job/sliced/input.rb index b1008cb..c82371f 100644 --- a/lib/rocket_job/sliced/input.rb +++ b/lib/rocket_job/sliced/input.rb @@ -105,7 +105,7 @@ def each_failed_record def requeue_failed failed.update_all( "$unset" => {worker_name: nil, started_at: nil}, - "$set" => {state: :queued} + "$set" => {state: "queued"} ) end @@ -113,7 +113,7 @@ def requeue_failed 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