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
187
188
189
190
191
|
# File 'app/models/naf/historical_job.rb', line 187
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
180
181
182
183
184
185
|
# File 'app/models/naf/historical_job.rb', line 180
def self.application_last_runs
where("application_schedule_id IS NOT NULL").
group("application_schedule_id").
select("application_schedule_id, MAX(finished_at) AS finished_at").
reject{ |job| job.finished_at.nil? }
end
|
.canceled ⇒ Object
176
177
178
|
# File 'app/models/naf/historical_job.rb', line 176
def self.canceled
where(request_to_terminate: true)
end
|
.connection ⇒ Object
*** Class Methods *** ++++++++++++++++++++++
156
157
158
|
# File 'app/models/naf/historical_job.rb', line 156
def self.connection
::Naf::NafBase.connection
end
|
.errored ⇒ Object
212
213
214
|
# File 'app/models/naf/historical_job.rb', line 212
def self.errored
where("finished_at IS NOT NULL AND exit_status > 0 OR request_to_terminate = true")
end
|
.finished ⇒ Object
193
194
195
|
# File 'app/models/naf/historical_job.rb', line 193
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
216
217
218
|
# File 'app/models/naf/historical_job.rb', line 216
def self.lock_for_job_queue(&block)
lock_record(0, &block)
end
|
.partition_num_lead_buffers ⇒ Object
168
169
170
|
# File 'app/models/naf/historical_job.rb', line 168
def self.partition_num_lead_buffers
10
end
|
.partition_table_size ⇒ Object
164
165
166
|
# File 'app/models/naf/historical_job.rb', line 164
def self.partition_table_size
100000
end
|
.queued_between(start_time, end_time) ⇒ Object
172
173
174
|
# File 'app/models/naf/historical_job.rb', line 172
def self.queued_between(start_time, end_time)
where(["created_at >= ? AND created_at <= ?", start_time, end_time])
end
|
.queued_status ⇒ Object
197
198
199
200
201
|
# File 'app/models/naf/historical_job.rb', line 197
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
208
209
210
|
# File 'app/models/naf/historical_job.rb', line 208
def self.queued_with_waiting
where("(started_at IS NULL AND request_to_terminate = false)")
end
|
.running_status ⇒ Object
203
204
205
206
|
# File 'app/models/naf/historical_job.rb', line 203
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
283
284
285
|
# File 'app/models/naf/historical_job.rb', line 283
def affinity_ids
historical_job_affinity_tabs.map{ |jat| jat.affinity_id }
end
|
#historical_job_affinity_tabs ⇒ Object
273
274
275
276
277
|
# File 'app/models/naf/historical_job.rb', line 273
def historical_job_affinity_tabs
::Naf::HistoricalJobAffinityTab.
from_partition(id).
where(historical_job_id: id)
end
|
#historical_job_prerequisites ⇒ Object
287
288
289
290
291
|
# File 'app/models/naf/historical_job.rb', line 287
def historical_job_prerequisites
::Naf::HistoricalJobPrerequisite.
from_partition(id).
where(historical_job_id: id)
end
|
#job_affinities ⇒ Object
279
280
281
|
# File 'app/models/naf/historical_job.rb', line 279
def job_affinities
historical_job_affinity_tabs.map{ |jat| jat.affinity }
end
|
#lock_for_runner_use(&block) ⇒ Object
316
317
318
|
# File 'app/models/naf/historical_job.rb', line 316
def lock_for_runner_use(&block)
advisory_lock(&block)
end
|
#machine_started_on_server_address ⇒ Object
269
270
271
|
# File 'app/models/naf/historical_job.rb', line 269
def machine_started_on_server_address
started_on_machine.try(:server_address)
end
|
#machine_started_on_server_name ⇒ Object
265
266
267
|
# File 'app/models/naf/historical_job.rb', line 265
def machine_started_on_server_name
started_on_machine.try(:server_name)
end
|
#prerequisites ⇒ Object
293
294
295
296
297
298
|
# File 'app/models/naf/historical_job.rb', line 293
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
312
313
314
|
# File 'app/models/naf/historical_job.rb', line 312
def spawn
application_type.spawn(self)
end
|
#title ⇒ Object
261
262
263
|
# File 'app/models/naf/historical_job.rb', line 261
def title
application.try(:title)
end
|
#to_s ⇒ Object
*** Instance Methods *** +++++++++++++++++++++++++
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
257
258
259
|
# File 'app/models/naf/historical_job.rb', line 224
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
|
#unlock_for_runner_use ⇒ Object
320
321
322
|
# File 'app/models/naf/historical_job.rb', line 320
def unlock_for_runner_use
advisory_unlock
end
|
#verify_prerequisites(these_jobs) ⇒ Object
XXX This should go away (it was moved to ConstructionZone::Foreman)
302
303
304
305
306
307
308
309
310
|
# File 'app/models/naf/historical_job.rb', line 302
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
|