Skip to content

Commit

Permalink
Add "running" jobs state (#253)
Browse files Browse the repository at this point in the history
This shows if any jobs are stuck and hanging out
  • Loading branch information
morgoth authored May 17, 2021
1 parent b144a49 commit db19e2c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions engine/app/controllers/good_job/dashboards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def jobs
sql = sql.finished
when 'unfinished'
sql = sql.unfinished
when 'running'
sql = sql.running
when 'errors'
sql = sql.where.not(error: nil)
end
Expand All @@ -33,6 +35,7 @@ def states
{
'finished' => GoodJob::Job.finished.count,
'unfinished' => GoodJob::Job.unfinished.count,
'running' => GoodJob::Job.running.count,
'errors' => GoodJob::Job.where.not(error: nil).count,
}
end
Expand Down
6 changes: 6 additions & 0 deletions lib/good_job/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ def self.queue_parser(string)
# @return [ActiveRecord::Relation]
scope :finished, ->(timestamp = nil) { timestamp ? where(arel_table['finished_at'].lteq(timestamp)) : 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

0 comments on commit db19e2c

Please sign in to comment.