1 class Arvados::V1::JobsController < ApplicationController
2 accept_attribute_as_json :script_parameters, Hash
3 accept_attribute_as_json :runtime_constraints, Hash
4 accept_attribute_as_json :tasks_summary, Hash
5 skip_before_filter :find_object_by_uuid, :only => :queue
8 want_ancestor = @where[:script_version_descends_from]
10 # Check for missing commit_ancestor rows, and create them if
14 includes(:commit_ancestors). # I wish Rails would let me
16 # commit_ancestors I am
19 if o.commit_ancestors.
20 select { |ca| ca.ancestor == want_ancestor }.
21 empty? and !o.script_version.nil?
23 o.commit_ancestors << CommitAncestor.find_or_create_by_descendant_and_ancestor(o.script_version, want_ancestor)
28 select { |ca| ca.ancestor == want_ancestor }.
32 # Now it is safe to do an .includes().where() because we are no
33 # longer interested in jobs that have other ancestors but not
36 includes(:commit_ancestors).
37 where('commit_ancestors.ancestor = ? and commit_ancestors.is = ?',
44 Q_UPDATE_INTERVAL = 12
45 def initialize(job, opts={})
51 yield "#{@job.uuid} finished at #{@job.finished_at}\n"
54 while not @job.started_at
55 # send a summary (job queue + available nodes) to the client
56 # every few seconds while waiting for the job to start
57 last_ack_at ||= Time.now - Q_UPDATE_INTERVAL - 1
58 if Time.now - last_ack_at >= Q_UPDATE_INTERVAL
59 nodes_in_state = {idle: 0, alloc: 0}
60 Node.where('hostname is not ?', nil).collect do |n|
61 if n.info[:slurm_state]
62 nodes_in_state[n.info[:slurm_state]] ||= 0
63 nodes_in_state[n.info[:slurm_state]] += 1
67 n_queued_before_me = 0
69 break if j.uuid == @job.uuid
70 n_queued_before_me += 1
74 " queue_position #{n_queued_before_me}" \
75 " queue_size #{job_queue.size}" \
76 " nodes_idle #{nodes_in_state[:idle]}" \
77 " nodes_alloc #{nodes_in_state[:alloc]}\n"
78 last_ack_at = Time.now
83 @redis = Redis.new(:timeout => 0)
84 @redis.subscribe(@job.uuid) do |event|
85 if @redis.exists @job.uuid
86 # A log buffer exists. Start by showing the last few KB.
88 getrange(@job.uuid, 0 - [@opts[:buffer_size], 1].max, -1).
89 sub(/^[^\n]*\n?/, '').
95 # TODO: avoid duplicating the last few lines of the log
96 # file. Use the fact that timestamps are lexicographically
98 event.message do |channel, msg|
100 @redis.unsubscribe @job.uuid
109 def self._log_tail_follow_requires_parameters
111 buffer_size: {type: 'integer', required: false}
115 if !@object.andand.uuid
116 return render_not_found
118 self.response.headers['Last-Modified'] = Time.now.ctime.to_s
119 self.response_body = LogStreamer.new @object, {
120 buffer_size: (params[:buffer_size] || 2**13)
128 is_locked_by_uuid: nil,
131 params[:order] ||= 'priority desc, created_at'
132 find_objects_for_index
136 def self._queue_requires_parameters
137 self._index_requires_parameters