Class: Kuroko2::JobInstancesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_user

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/kuroko2/job_instances_controller.rb', line 11

def create
  if params[:job_definition].present?
    @instance = @definition.job_instances.create(params.require(:job_definition).permit(:script))
  else
    @instance = @definition.job_instances.create
  end

  if @instance
    @instance.logs.info("Launched by #{current_user.name}.")

    redirect_to job_definition_job_instance_path(@definition, @instance)
  else
    raise HTTP::BadRequest
  end
end

#destroyObject



38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/kuroko2/job_instances_controller.rb', line 38

def destroy
  if @instance.cancelable?
    ActiveRecord::Base.transaction { @instance.cancel }

    message = "This job was canceled by #{current_user.name}."
    @instance.logs.warn(message)
    Kuroko2.logger.warn(message)
  end

  redirect_to job_definition_job_instance_path(@definition, @instance)
end

#force_destroyObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/kuroko2/job_instances_controller.rb', line 50

def force_destroy
  ActiveRecord::Base.transaction do
    @instance.executions.each do |execution|
      execution = Kuroko2::Worker.executing(execution.id)
      execution.update_column(:execution_id, nil) if execution
    end

    @instance.cancel
  end

  message = "Force canceled by #{current_user.name}."
  @instance.logs.warn(message)
  Kuroko2.logger.warn(message)

  redirect_to job_definition_job_instance_path(@definition, @instance)
end

#indexObject



5
6
7
8
9
# File 'app/controllers/kuroko2/job_instances_controller.rb', line 5

def index
  @instances = @definition.job_instances.page(page_params[:page])

  render layout: false
end

#showObject



27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/kuroko2/job_instances_controller.rb', line 27

def show
  @logs   = @instance.logs
  @tokens = @instance.tokens

  if params[:mode] == :naked
    render partial: 'instance', layout: false
  else
    # render
  end
end

#workingObject



67
68
69
# File 'app/controllers/kuroko2/job_instances_controller.rb', line 67

def working
  @instances = Kuroko2::JobInstance.working.order(id: :desc).joins(job_definition: :admins).includes(job_definition: :admins)
end