Class: Logical::Naf::JobStatuses::Running

Inherits:
Object
  • Object
show all
Defined in:
app/models/logical/naf/job_statuses/running.rb

Class Method Summary collapse

Class Method Details

.all(status = :running, conditions) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/logical/naf/job_statuses/running.rb', line 6

def self.all(status = :running, conditions)
  if status == :queued
    order = "created_at"
    direction = "desc"
  else
    order = "started_at"
    direction = "desc"
  end
  <<-SQL
    (
      SELECT
        j.*, null AS "historical_job_id"
      FROM
        "#{::Naf.schema_name}"."historical_jobs" AS j
      WHERE
        j.started_at IS NOT NULL AND
        j.finished_at IS NULL AND
        j.request_to_terminate = false
      #{conditions}
      ORDER BY
        #{order} #{direction}
    )
  SQL
end