Class: JobController

Inherits:
ApplicationController show all
Defined in:
app/controllers/job_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#sort_key

Instance Method Details

#gen_client_listsObject



72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/job_controller.rb', line 72

def gen_client_lists
  @client_list = []
  @platform_list = []
  Client.find(:all, :select => 'name, uname').each { |client|
    @client_list << client[:name]
    platform = client[:uname].split(',')[1]
    platform and platform.capitalize!
    @platform_list.include?(platform) or @platform_list << platform
  }
end

#indexObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/job_controller.rb', line 29

def index
  @page_title = "Jobs"
  where = []
  wargs = []
  if params[:days].to_i != 0
    today = Time::parse(TODAY || "now")
    where << "schedtime > ?"
    wargs << params[:days].to_i.day.ago(today).midnight.tomorrow
  end
  if params[:name] != '0'
    where << "name = ?"
    wargs << params[:name]
  end
  if params[:err].to_i == 1
    where << "jobstatus != 'T'"
  end

  fargs = {}
  fargs[:select] = "*, " +
    "case when (endtime > starttime) then " +
    ( MYSQL ?
        "jobbytes / (endtime - starttime) " :
        "jobbytes / extract(epoch from endtime - starttime) " ) +
    "else null end as rate, " +
    "cast(endtime-starttime as time) as time"
  fargs[:order] = sort_key(:jsort, key_sql)
  if where.size != 0
    fargs[:conditions] = [ where.join(' and '), wargs ].flatten!
  end
  @jobs = Job.find(:all, fargs)
end

#key_sqlObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/job_controller.rb', line 15

def key_sql
  { "id"     => "jobid",     "id-"   => "jobid desc", 
    "name"   => "name",      "name-"   => "name desc", 
    "type"   => "type",      "type-"   => "type desc",
    "level"  => "level",     "level-"  => "level desc",
    "status" => "jobstatus", "status-" => "jobstatus desc",
    "bytes"  => "jobbytes",  "bytes-"  => "jobbytes desc",
    "rate"   => "rate",      "rate-"   => "rate desc",
    "time"   => "time",      "time-"   => "time desc",
    "sched"  => "schedtime", "sched-"  => "schedtime desc",
    "start"  => "starttime", "start-"  => "starttime desc",
    "finish" => "endtime",   "finish-" => "endtime desc", }
end

#lastObject



92
93
94
95
96
97
98
# File 'app/controllers/job_controller.rb', line 92

def last
  name = params[:name]
  @page_title = name
  @full = last_job(name, "F")
  @diff = last_job(name, "D")
  @incr = last_job(name, "I")
end

#last_job(name, level) ⇒ Object



83
84
85
86
87
88
89
90
# File 'app/controllers/job_controller.rb', line 83

def last_job(name, level)
  Job.find(:first,
    :select => "StartTime, JobFiles, JobBytes",
    :order => "starttime desc",
    :conditions =>
      [ "type='B' and jobstatus='T' and level=? and name=? ",
        level, name ] )
end

#showObject



61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/job_controller.rb', line 61

def show
  jid = params[:jid]
  @page_title = "Job " + jid
  params[:action] = params[:jid] = nil
  @job = Job.find(jid)
  @jobmedia = Jobmedia.find_by_sql(
    'select mediaid,volumename from Media where mediaid in ' +
    '  (select distinct mediaid from JobMedia where jobid = ' + jid + 
    '  ) order by mediaid' )
end

#spec_to_paramsObject



4
5
6
7
8
9
10
11
12
13
# File 'app/controllers/job_controller.rb', line 4

def spec_to_params
  if params["commit"]
    params.delete("commit")
    if params["spec"]
      params["name"] = params["spec"]["name"] if params["spec"]["name"]
      params["days"] = params["spec"]["days"] if params["spec"]["days"]
      params.delete("spec")
    end
  end
end