Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
    stree write --print-width=120 lib/**.rb spec/**.rb delayed_job_modern_record.gemspec Gemfile
  • Loading branch information
mostlyobvious committed Mar 11, 2024
1 parent 85ca3a5 commit 041b677
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 23 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ gemspec
gem "mysql2", "~> 0.5.6"
gem "trilogy", "~> 2.7.0"
gem "rspec", "~> 3.13"

14 changes: 7 additions & 7 deletions delayed_job_modern_record.gemspec
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# frozen_string_literal: true

Gem::Specification.new do |spec|
spec.name = "delayed_job_moden_record"
spec.version = "0.0.1"
spec.summary = "Modern ActiveRecord backend for DelayedJob"
spec.name = "delayed_job_moden_record"
spec.version = "0.0.1"
spec.summary = "Modern ActiveRecord backend for DelayedJob"
spec.description = "Modern ActiveRecord backend for Delayed::Job, originally authored by Tobias Lütke"

spec.licenses = "MIT"

spec.authors = ["Arkency"]
spec.email = ["dev@arkency.com"]
spec.authors = ["Arkency"]
spec.email = ["dev@arkency.com"]
spec.homepage = "http://github.com/arkency/delayed_job_modern_record"

spec.files = %w[CONTRIBUTING.md LICENSE.md README.md delayed_job_modern_record.gemspec] + Dir["lib/**/*.rb"]
spec.files = %w[CONTRIBUTING.md LICENSE.md README.md delayed_job_modern_record.gemspec] + Dir["lib/**/*.rb"]
spec.require_paths = ["lib"]

spec.metadata = { "rubygems_mfa_required" => "true" }

spec.required_ruby_version = ">= 3.3.0"

spec.add_dependency "activerecord", [">= 7.1", "< 8.0"]
spec.add_dependency "delayed_job", [">= 4.1.11", "< 5"]
spec.add_dependency "delayed_job", [">= 4.1.11", "< 5"]
end
16 changes: 3 additions & 13 deletions lib/delayed/backend/modern_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,15 @@ def self.ready_to_run(worker_name, max_run_time)
)
end

def self.before_fork
::ActiveRecord::Base.connection_handler.clear_all_connections!(:all)
end

def self.after_fork
::ActiveRecord::Base.establish_connection
end
def self.before_fork = ::ActiveRecord::Base.connection_handler.clear_all_connections!(:all)
def self.after_fork = ::ActiveRecord::Base.establish_connection

def self.clear_locks!(worker_name)
where(locked_by: worker_name).update_all(locked_by: nil, locked_at: nil)
end

def self.reserve(worker, max_run_time = Worker.max_run_time)
ready_scope =
ready_to_run(worker.name, max_run_time)
.min_priority
.max_priority
.for_queues
.by_priority
ready_scope = ready_to_run(worker.name, max_run_time).min_priority.max_priority.for_queues.by_priority

now = db_time_now.change(usec: 0)
count = ready_scope.limit(1).update_all(locked_at: now, locked_by: worker.name)
Expand Down
2 changes: 1 addition & 1 deletion lib/delayed_job_modern_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
require "delayed_job"
require "delayed/backend/modern_record"

Delayed::Worker.backend = Delayed::Backend::ModernRecord::Job
Delayed::Worker.backend = Delayed::Backend::ModernRecord::Job
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ def whatever(number) = tell * number

default_scope { where(scoped: true) }
handle_asynchronously :whatever
end
end

0 comments on commit 041b677

Please sign in to comment.