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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'app/controllers/level_up/jobs_controller.rb', line 80

def graphviz
  job = Job.find params[:id]
  g = GraphViz.new(:G, type: :digraph)
  g[:bgcolor]= '#fafbfb'

  g.node[:color] = '#111111'
  g.node[:style] = 'filled'
  g.node[:shape] = 'box'
  g.node[:fillcolor] = '#666666'
  g.node[:fontcolor] = 'white'
  g.node[:fontname] = 'Verdana'
  g.edge[:color] = '#000000'
  g.edge[:arrowhead] = 'open'

  states = {}
  job.states.each do |state|
    states[state] = g.add_nodes(state.to_s.humanize.downcase)
    if state == :start
      states[state][:fillcolor] = '#5db1a4'
      states[state][:color] = '#048282'

    elsif state == :end
      states[state][:fillcolor] = '#b40d28'
      states[state][:color] = '#600615'
    end
  end

  job.states.each do |state|
    job.transitions(state).each do |transition|
      g.add_edges(states[state], states[transition])
    end
  end

  g.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')
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[:state])
    redirect_to job_path(j), notice: "Moved to #{params[:state]}!"
  else
    flash[:error] = "Error while moving to #{params[:state]}"
    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.event!(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