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
# File 'app/controllers/kuroko2/job_instances_controller.rb', line 11

def create
  creation_params = { launched_by: current_user.name }
  if params[:job_definition].present?
    creation_params.merge!(params.require(:job_definition).permit(:script).to_h.symbolize_keys)
  end

  @instance = @definition.create_instance(**creation_params)
  redirect_to job_definition_job_instance_path(@definition, @instance)
end

#destroyObject



32
33
34
35
36
37
38
# File 'app/controllers/kuroko2/job_instances_controller.rb', line 32

def destroy
  if @instance.cancelable?
    ActiveRecord::Base.transaction { @instance.cancel(by: current_user.name) }
  end

  redirect_to job_definition_job_instance_path(@definition, @instance)
end

#force_destroyObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/kuroko2/job_instances_controller.rb', line 40

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(by: current_user.name)
  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



21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/kuroko2/job_instances_controller.rb', line 21

def show
  @logs   = @instance.logs.order(:id)
  @tokens = @instance.tokens.order(:id)

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

#workingObject



57
58
59
# File 'app/controllers/kuroko2/job_instances_controller.rb', line 57

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