Class: Naf::HistoricalJob
- Inherits:
-
Partitioned::ById
- Object
- Partitioned::ById
- Naf::HistoricalJob
show all
- Includes:
- PgAdvisoryLocker
- Defined in:
- app/models/naf/historical_job.rb
Overview
Things you should know about jobs new jobs older than 1.week will not be searched in the queue. You should not run programs for more than a 1.week (instead, have them exit and restarted periodically)
Defined Under Namespace
Classes: JobPrerequisiteLoop
Constant Summary
collapse
- JOB_STALE_TIME =
1.week
- SYSTEM_TAGS =
{
startup: '$startup',
pre_work: '$pre-work',
work: '$work',
cleanup: '$cleanup'
}
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.application_last_queued ⇒ Object
184
185
186
187
188
|
# File 'app/models/naf/historical_job.rb', line 184
def self.application_last_queued
where("application_id IS NOT NULL").
group("application_id").
select("application_id, MAX(id) AS id, MAX(created_at) AS created_at")
end
|
.application_last_runs ⇒ Object
177
178
179
180
181
182
|
# File 'app/models/naf/historical_job.rb', line 177
def self.application_last_runs
where("application_id IS NOT NULL").
group("application_id").
select("application_id, MAX(finished_at) AS finished_at").
reject{ |job| job.finished_at.nil? }
end
|
.canceled ⇒ Object
173
174
175
|
# File 'app/models/naf/historical_job.rb', line 173
def self.canceled
where(request_to_terminate: true)
end
|
.connection ⇒ Object
*** Class Methods *** ++++++++++++++++++++++
153
154
155
|
# File 'app/models/naf/historical_job.rb', line 153
def self.connection
::Naf::NafBase.connection
end
|
.errored ⇒ Object
209
210
211
|
# File 'app/models/naf/historical_job.rb', line 209
def self.errored
where("finished_at IS NOT NULL AND exit_status > 0 OR request_to_terminate = true")
end
|
.finished ⇒ Object
190
191
192
|
# File 'app/models/naf/historical_job.rb', line 190
def self.finished
where("finished_at IS NOT NULL OR request_to_terminate = true")
end
|
.full_table_name_prefix ⇒ Object
.lock_for_job_queue(&block) ⇒ Object
213
214
215
|
# File 'app/models/naf/historical_job.rb', line 213
def self.lock_for_job_queue(&block)
lock_record(0, &block)
end
|
.partition_num_lead_buffers ⇒ Object
165
166
167
|
# File 'app/models/naf/historical_job.rb', line 165
def self.partition_num_lead_buffers
10
end
|
.partition_table_size ⇒ Object
161
162
163
|
# File 'app/models/naf/historical_job.rb', line 161
def self.partition_table_size
100000
end
|
.queued_between(start_time, end_time) ⇒ Object
169
170
171
|
# File 'app/models/naf/historical_job.rb', line 169
def self.queued_between(start_time, end_time)
where(["created_at >= ? AND created_at <= ?", start_time, end_time])
end
|
.queued_status ⇒ Object
194
195
196
197
198
|
# File 'app/models/naf/historical_job.rb', line 194
def self.queued_status
where("(started_at IS NULL AND request_to_terminate = false) OR
(finished_at > '#{Time.zone.now - 1.minute}') OR
(started_at IS NOT NULL AND finished_at IS NULL AND request_to_terminate = false)")
end
|
.queued_with_waiting ⇒ Object
205
206
207
|
# File 'app/models/naf/historical_job.rb', line 205
def self.queued_with_waiting
where("(started_at IS NULL AND request_to_terminate = false)")
end
|
.running_status ⇒ Object
200
201
202
203
|
# File 'app/models/naf/historical_job.rb', line 200
def self.running_status
where("(started_at IS NOT NULL AND finished_at IS NULL AND request_to_terminate = false) OR
(finished_at > '#{Time.zone.now - 1.minute}')")
end
|
Instance Method Details
#affinity_ids ⇒ Object
280
281
282
|
# File 'app/models/naf/historical_job.rb', line 280
def affinity_ids
historical_job_affinity_tabs.map{ |jat| jat.affinity_id }
end
|
#historical_job_affinity_tabs ⇒ Object
270
271
272
273
274
|
# File 'app/models/naf/historical_job.rb', line 270
def historical_job_affinity_tabs
::Naf::HistoricalJobAffinityTab.
from_partition(id).
where(historical_job_id: id)
end
|
#historical_job_prerequisites ⇒ Object
284
285
286
287
288
|
# File 'app/models/naf/historical_job.rb', line 284
def historical_job_prerequisites
::Naf::HistoricalJobPrerequisite.
from_partition(id).
where(historical_job_id: id)
end
|
#job_affinities ⇒ Object
276
277
278
|
# File 'app/models/naf/historical_job.rb', line 276
def job_affinities
historical_job_affinity_tabs.map{ |jat| jat.affinity }
end
|
#machine_started_on_server_address ⇒ Object
266
267
268
|
# File 'app/models/naf/historical_job.rb', line 266
def machine_started_on_server_address
started_on_machine.try(:server_address)
end
|
#machine_started_on_server_name ⇒ Object
262
263
264
|
# File 'app/models/naf/historical_job.rb', line 262
def machine_started_on_server_name
started_on_machine.try(:server_name)
end
|
#prerequisites ⇒ Object
290
291
292
293
294
295
|
# File 'app/models/naf/historical_job.rb', line 290
def prerequisites
historical_job_prerequisites.
map{ |hjp| ::Naf::HistoricalJob.from_partition(hjp.prerequisite_historical_job_id).
find_by_id(hjp.prerequisite_historical_job_id) }.
reject{ |j| j.nil? }
end
|
#spawn ⇒ Object
309
310
311
|
# File 'app/models/naf/historical_job.rb', line 309
def spawn
application_type.spawn(self)
end
|
#title ⇒ Object
258
259
260
|
# File 'app/models/naf/historical_job.rb', line 258
def title
application.try(:title)
end
|
#to_s ⇒ Object
*** Instance Methods *** +++++++++++++++++++++++++
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
# File 'app/models/naf/historical_job.rb', line 221
def to_s
components = []
if started_at.nil?
components << "QUEUED"
else
if finished_at.nil?
if pid
= []
<< pid.to_s
<< 'RequestedToTerminate' if request_to_terminate
components << "RUNNING:#{.join(':')}"
else
components << "SPAWNING"
end
else
= []
<< 'RequestedToTerminate' if request_to_terminate
<< "FailedToStart" if failed_to_start
<< "SIG#{termination_signal}" if termination_signal
if exit_status && exit_status != 0
<< "STATUS=#{exit_status}"
end
if .length
= " (#{.join(',')})"
else
= ""
end
components << "FINISHED#{}"
end
end
components << "id: #{id}"
components << "\"#{command}\""
return "::Naf::HistoricalJob<#{components.join(', ')}>"
end
|
#verify_prerequisites(these_jobs) ⇒ Object
XXX This should go away (it was moved to ConstructionZone::Foreman)
299
300
301
302
303
304
305
306
307
|
# File 'app/models/naf/historical_job.rb', line 299
def verify_prerequisites(these_jobs)
these_jobs.each do |this_job|
if this_job.id == id
raise JobPrerequisiteLoop.new(self)
else
verify_prerequisites(this_job.prerequisites)
end
end
end
|