Class: Naf::HistoricalJobsController

Inherits:
ApplicationController show all
Includes:
ApplicationHelper
Defined in:
app/controllers/naf/historical_jobs_controller.rb

Constant Summary

Constants included from ApplicationHelper

ApplicationHelper::NAF_ALL_VISIBLE_RESOURCES, ApplicationHelper::NAF_CREATE_BLOCKED_RESOURCES, ApplicationHelper::NAF_DESTROY_BLOCKED_RESOURCES, ApplicationHelper::NAF_READ_ONLY_RESOURCES

Instance Method Summary collapse

Methods included from ApplicationHelper

#add_color, #http_protocol, #naf_display_job_search_link?, #naf_generate_back_link, #naf_generate_child_resources_link, #naf_generate_create_link, #naf_generate_destroy_link, #naf_generate_edit_link, #naf_generate_index_link, #naf_highlight_tab?, #naf_last_queued_at_link, #naf_link_to_add_fields, #naf_link_to_remove_fields, #naf_make_header, #naf_model_name, #naf_nested_resource_index?, #naf_parent_resource_link, #naf_table_title, #naf_tabs

Instance Method Details

#createObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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
# File 'app/controllers/naf/historical_jobs_controller.rb', line 47

def create
  @historical_job = Naf::HistoricalJob.new(params[:historical_job])
  if params[:historical_job][:application_id] &&
    app = Naf::Application.find(params[:historical_job][:application_id])

    if schedule = app.application_schedules.first
      @historical_job = ::Logical::Naf::ConstructionZone::Boss.new.enqueue_application_schedule(schedule)
      if @historical_job.blank?
        render json: {
          success: false,
          title: ::Naf::Application.find_by_id(params[:historical_job][:application_id]).title
        }.to_json

        return
      end
    else
      @historical_job.command = app.command
      @historical_job.application_type_id = app.application_type_id
      @historical_job.application_run_group_restriction_id =
        Naf::ApplicationRunGroupRestriction.no_limit.id
      @queued_job = ::Naf::QueuedJob.new
    end
  else
    @queued_job = ::Naf::QueuedJob.new
  end

  if @queued_job.present?
    @queued_job.application_type_id = @historical_job.application_type_id
    @queued_job.command = @historical_job.command
    @queued_job.application_run_group_restriction_id =
      @historical_job.application_run_group_restriction_id
    @queued_job.application_run_group_name = @historical_job.application_run_group_name
    @queued_job.application_run_group_limit = @historical_job.application_run_group_limit
    @queued_job.priority = @historical_job.priority
  end

  respond_to do |format|
    format.json do
      if @historical_job.save
        if @queued_job.present?
          @queued_job.id = @historical_job.id
          @queued_job.save
        end

        render json: { success: true,
                       title: @historical_job.title,
                       command: @historical_job.command }.to_json
      end
    end

    format.html do
      if @historical_job.save
        if @queued_job.present?
          @queued_job.id = @historical_job.id
          @queued_job.save
        end

        redirect_to(@historical_job,
                    notice: "Job '#{@historical_job.command}' was successfully created.")
      else
        render action: "new"
      end
    end
  end
end

#indexObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/naf/historical_jobs_controller.rb', line 9

def index
  respond_to do |format|
    format.html
    format.json do
      set_page
      set_status

      params[:search][:direction] = params['sSortDir_0']
      params[:search][:order] = Logical::Naf::Job::ORDER[params['iSortCol_0']]
      params[:search][:limit] = params['iDisplayLength']
      params[:search][:offset] = @page - 1
      @total_display_records = Logical::Naf::Job.total_display_records(params[:search])
      @total_records = Naf::HistoricalJob.count(:all)
      @historical_jobs = []
      job =[]
      Logical::Naf::Job.search(params[:search]).map(&:to_hash).map do |hash|
        add_urls(hash).map do |key, value|
          value ||= ''
          job << value
        end
        @historical_jobs << job
        job = []
      end

      render layout: 'naf/layouts/jquery_datatables'
    end
  end
end

#newObject



43
44
45
# File 'app/controllers/naf/historical_jobs_controller.rb', line 43

def new
  @historical_job = Naf::HistoricalJob.new
end

#showObject



38
39
40
41
# File 'app/controllers/naf/historical_jobs_controller.rb', line 38

def show
  @historical_job = Naf::HistoricalJob.find(params[:id])
  @logical_job = Logical::Naf::Job.new(@historical_job)
end

#updateObject



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'app/controllers/naf/historical_jobs_controller.rb', line 113

def update
  respond_to do |format|
    @historical_job = Naf::HistoricalJob.find(params[:id])
    if @historical_job.update_attributes(params[:historical_job])

      ::Naf::HistoricalJob.lock_for_job_queue do
        if params[:historical_job][:request_to_terminate].present?
          if queued_job = ::Naf::QueuedJob.find_by_id(params[:id])
            @historical_job.finished_at = Time.zone.now
            @historical_job.save!
            queued_job.delete
          end

          if running_job = ::Naf::RunningJob.find_by_id(params[:id])
            running_job.update_attributes(request_to_terminate: true)
            @historical_job.update_attributes(request_to_terminate: true)
          end
        end

        format.html do
          redirect_to(
            @historical_job,
            notice: "Job '#{@historical_job.command}' was successfully updated."
          )
        end
        format.json do
          render json: { success: true,
                         title: @historical_job.title,
                         command: @historical_job.command }.to_json
        end
      end
    else
      format.html do
        render action: "edit"
      end
      format.json do
        render json: { success: false }.to_json
      end
    end
  end
end