Class: LevelUp::JobsController

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

Instance Method Summary collapse

Instance Method Details

#destroyObject



41
42
43
44
45
# File 'app/controllers/level_up/jobs_controller.rb', line 41

def destroy
  job = Job.find params[:id]
  job.destroy
  redirect_to jobs_path, notice: "Job destroyed!"
end

#editObject



28
29
30
# File 'app/controllers/level_up/jobs_controller.rb', line 28

def edit
  @job = Job.find params[:id]
end

#graphvizObject



80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/level_up/jobs_controller.rb', line 80

def graphviz
  job = Job.find params[:id]

  if job
    builder = GraphBuilder.new(job)
    graph = builder.graph
    graph.output(:svg => "#{Rails.root}/tmp/job_#{job.id}.svg")
    send_data(File.open("#{Rails.root}/tmp/job_#{job.id}.svg").read, filename: "job_#{job.id}.svg", type: 'image/svg+xml', disposition: 'inline')
  else
    render text: "Job not found", status: 404
  end
end

#indexObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/level_up/jobs_controller.rb', line 9

def index
  @search_params = params[:search] || {}
  @query_params = @search_params.dup

  if @query_params[:delayed_job_id_eq] == 'true'
    @query_params[:delayed_job_id_is_not_null] = true
  elsif @query_params[:delayed_job_id_eq] == 'false'
    @query_params[:delayed_job_id_is_null] = true
  end
  @query_params.delete :delayed_job_id_eq

  @search = Job.search(@query_params)
  @jobs = @search.relation.page(params[:page]).per(20)
end

#moveObject



69
70
71
72
73
74
75
76
77
# File 'app/controllers/level_up/jobs_controller.rb', line 69

def move
  job = Job.find params[:id]
  if job.boot_async!(params[:task])
    redirect_to job_path(job), notice: "Moved to #{params[:task]}!"
  else
    flash[:error] = "Error while moving to #{params[:task]}"
    redirect_to job_path(job)
  end
end

#rebootObject



59
60
61
62
63
64
65
66
67
# File 'app/controllers/level_up/jobs_controller.rb', line 59

def reboot
  job = Job.find params[:id]
  if job.boot_async!
    redirect_to job_path(job), notice: 'Rebooted!'
  else
    flash[:error] = 'Error while rebooting'
    redirect_to job_path(job)
  end
end

#runObject



53
54
55
56
57
# File 'app/controllers/level_up/jobs_controller.rb', line 53

def run
  job = Job.find params[:id]
  job.boot!(nil, false, false)
  redirect_to job_path(job), notice: 'Run!'
end

#showObject



24
25
26
# File 'app/controllers/level_up/jobs_controller.rb', line 24

def show
  @job = Job.find params[:id]
end

#unqueueObject



47
48
49
50
51
# File 'app/controllers/level_up/jobs_controller.rb', line 47

def unqueue
  job = Job.find params[:id]
  job.unqueue!
  redirect_to job_path(job), notice: 'Unqueued!'
end

#updateObject



32
33
34
35
36
37
38
39
# File 'app/controllers/level_up/jobs_controller.rb', line 32

def update
  @job = Job.find params[:id]
  if @job.update_attributes(params[:job])
    redirect_to job_path(@job), notice: 'Changes saved!'
  else
    render :edit
  end
end