Skip to content

Commit

Permalink
All running jobs now have performed_at set so use that in status qu…
Browse files Browse the repository at this point in the history
…ery; fix flaky test that took advisory lock in `before` block (#1444)
  • Loading branch information
bensheldon authored Jul 19, 2024
1 parent fbd216f commit fa3660d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
4 changes: 2 additions & 2 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(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))).joins_advisory_locks.where(pg_locks: { locktype: nil }) }
# Advisory locked and executing
scope :running, -> { where(finished_at: nil).joins_advisory_locks.where.not(pg_locks: { locktype: nil }) }
scope :running, -> { where.not(performed_at: nil).where(finished_at: nil).joins_advisory_locks.where.not(pg_locks: { locktype: nil }) }
# Finished executing (succeeded or discarded)
scope :finished, -> { where.not(finished_at: nil) }
# Completed executing successfully
Expand Down
6 changes: 1 addition & 5 deletions spec/app/filters/good_job/jobs_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@
running_active_job = ExampleJob.perform_later('success')
running_job = GoodJob::Job.find(running_active_job.provider_job_id)
running_job.update!(
performed_at: 1.minute.ago,
finished_at: nil
)
running_job.advisory_lock
end

after do
GoodJob::Job.advisory_unlock_session
end

describe '#job_classes' do
Expand Down

0 comments on commit fa3660d

Please sign in to comment.