Skip to content

Commit

Permalink
Fix a few method redefinition warnings (#1459)
Browse files Browse the repository at this point in the history
* Fix a few method redefinition warnings

2 enum values conflict with already existing scopes: "retried" and "discarded" (#1420)
"running" and "finished" got moved from the discrete execution (#1427)

* Use the simpler version of finished; use queued/running without checking advisory locks

---------

Co-authored-by: Ben Sheldon [he/him] <[email protected]>
  • Loading branch information
Earlopain and bensheldon authored Aug 8, 2024
1 parent a19bd1d commit 72ba713
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 24 deletions.
4 changes: 2 additions & 2 deletions app/models/concerns/good_job/error_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ module ErrorEvents
discarded: 5,
}
if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1.0.a')
enum :error_event, error_event_enum, validate: { allow_nil: true }
enum :error_event, error_event_enum, validate: { allow_nil: true }, scopes: false
else
enum error_event: error_event_enum
enum error_event: error_event_enum, _scopes: false
end
end
end
Expand Down
22 changes: 2 additions & 20 deletions app/models/good_job/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ class Job < BaseRecord
# Execution errored, will run in the future
scope :retried, -> { where(finished_at: nil).where(coalesce_scheduled_at_created_at.gt(bind_value('coalesce', Time.current, ActiveRecord::Type::DateTime))).where(params_execution_count.gt(1)) }
# Immediate/Scheduled time to run has passed, waiting for an available thread run
scope :queued, -> { where(performed_at: nil, finished_at: nil).where(coalesce_scheduled_at_created_at.lteq(bind_value('coalesce', Time.current, ActiveRecord::Type::DateTime))).joins_advisory_locks.where(pg_locks: { locktype: nil }) }
scope :queued, -> { where(performed_at: nil, finished_at: nil).where(coalesce_scheduled_at_created_at.lteq(bind_value('coalesce', Time.current, ActiveRecord::Type::DateTime))) }
# Advisory locked and executing
scope :running, -> { where.not(performed_at: nil).where(finished_at: nil).joins_advisory_locks.where.not(pg_locks: { locktype: nil }) }
scope :running, -> { where.not(performed_at: nil).where(finished_at: nil) }
# Finished executing (succeeded or discarded)
scope :finished, -> { where.not(finished_at: nil) }
# Completed executing successfully
Expand Down Expand Up @@ -140,24 +140,6 @@ class Job < BaseRecord
# @return [ActiveRecord::Relation]
scope :schedule_ordered, -> { order(coalesce_scheduled_at_created_at.asc) }

# Get completed jobs before the given timestamp. If no timestamp is
# provided, get *all* completed jobs. By default, GoodJob
# destroys jobs after they're completed, meaning this returns no jobs.
# However, if you have changed {GoodJob.preserve_job_records}, this may
# find completed Jobs.
# @!method finished(timestamp = nil)
# @!scope class
# @param timestamp (Float)
# Get jobs that finished before this time (in epoch time).
# @return [ActiveRecord::Relation]
scope :finished, ->(timestamp = nil) { timestamp ? where(arel_table['finished_at'].lteq(bind_value('finished_at', timestamp, ActiveRecord::Type::DateTime))) : where.not(finished_at: nil) }

# Get Jobs that started but not finished yet.
# @!method running
# @!scope class
# @return [ActiveRecord::Relation]
scope :running, -> { where.not(performed_at: nil).where(finished_at: nil) }

# Get Jobs on queues that match the given queue string.
# @!method queue_string(string)
# @!scope class
Expand Down
4 changes: 2 additions & 2 deletions app/models/good_job/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class Process < BaseRecord
advisory: 0,
}
if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1.0.a')
enum :lock_type, lock_type_enum, validate: { allow_nil: true }
enum :lock_type, lock_type_enum, validate: { allow_nil: true }, scopes: false
else
enum lock_type: lock_type_enum
enum lock_type: lock_type_enum, _scopes: false
end

has_many :locked_jobs, class_name: "GoodJob::Job", foreign_key: :locked_by_id, inverse_of: :locked_by_process, dependent: nil
Expand Down

0 comments on commit 72ba713

Please sign in to comment.