Class: Barbeque::JobDefinitionsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/barbeque/job_definitions_controller.rb', line 26

def create
  attributes = new_job_definition_params.merge(command: command_array)
  @job_definition = Barbeque::JobDefinition.new(attributes)

  if @job_definition.save
    redirect_to @job_definition, notice: 'Job definition was successfully created.'
  else
    render :new
  end
end

#destroyObject



50
51
52
53
54
55
56
57
# File 'app/controllers/barbeque/job_definitions_controller.rb', line 50

def destroy
  @job_definition = Barbeque::JobDefinition.find(params[:id])
  @job_definition.sns_subscriptions.each do |sns_subscription|
    Barbeque::SNSSubscriptionService.new.unsubscribe(sns_subscription)
  end
  @job_definition.destroy
  redirect_to job_definitions_url, notice: 'Job definition was successfully destroyed.'
end

#editObject



19
20
21
22
23
24
# File 'app/controllers/barbeque/job_definitions_controller.rb', line 19

def edit
  @job_definition = Barbeque::JobDefinition.find(params[:id])
  if @job_definition.slack_notification.nil?
    @job_definition.build_slack_notification
  end
end

#execution_statsObject



64
65
66
67
68
69
# File 'app/controllers/barbeque/job_definitions_controller.rb', line 64

def execution_stats
  job_definition = Barbeque::JobDefinition.find(params[:job_definition_id])
  days = (params[:days] || 3).to_i
  now = Time.zone.now
  render json: job_definition.execution_stats(days.days.ago(now), now)
end

#indexObject



2
3
4
# File 'app/controllers/barbeque/job_definitions_controller.rb', line 2

def index
  @job_definitions = Barbeque::JobDefinition.all
end

#newObject



11
12
13
14
15
16
17
# File 'app/controllers/barbeque/job_definitions_controller.rb', line 11

def new
  @job_definition = Barbeque::JobDefinition.new
  @job_definition.build_slack_notification
  if params[:job_definition]
    @job_definition.assign_attributes(new_job_definition_params)
  end
end

#showObject



6
7
8
9
# File 'app/controllers/barbeque/job_definitions_controller.rb', line 6

def show
  @job_definition = Barbeque::JobDefinition.find(params[:id])
  @job_executions = @job_definition.job_executions.order(id: :desc).page(params[:page])
end

#statsObject



59
60
61
62
# File 'app/controllers/barbeque/job_definitions_controller.rb', line 59

def stats
  @job_definition = Barbeque::JobDefinition.find(params[:job_definition_id])
  @days = (params[:days] || 3).to_i
end

#updateObject



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

def update
  @job_definition = Barbeque::JobDefinition.find(params[:id])
  attributes = params.require(:job_definition).permit(
    :description,
    slack_notification_attributes: slack_notification_params,
  ).merge(command: command_array)
  if @job_definition.update(attributes)
    redirect_to @job_definition, notice: 'Job definition was successfully updated.'
  else
    render :edit
  end
end