X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e46ae4015db8f166359515f2e9823ac1a2c7cab8..bdb71f7762196e179e495bda28f4375e5c69af31:/services/api/script/crunch-dispatch.rb?ds=sidebyside diff --git a/services/api/script/crunch-dispatch.rb b/services/api/script/crunch-dispatch.rb index ecc7f5d98e..3635846030 100755 --- a/services/api/script/crunch-dispatch.rb +++ b/services/api/script/crunch-dispatch.rb @@ -38,6 +38,7 @@ class Dispatcher def refresh_todo @todo = Job.queue + @todo_pipelines = PipelineInstance.queue end def sinfo @@ -297,7 +298,6 @@ class Dispatcher job_done = j_done[:job] $stderr.puts "dispatch: child #{pid_done} exit" $stderr.puts "dispatch: job #{job_done.uuid} end" - $redis.publish job_done.uuid, "end" # Ensure every last drop of stdout and stderr is consumed read_pipes @@ -308,12 +308,29 @@ class Dispatcher # Wait the thread j_done[:wait_thr].value + jobrecord = Job.find_by_uuid(job_done.uuid) + jobrecord.assert_finished + jobrecord.save! + # Invalidate the per-job auth token j_done[:job_auth].update_attributes expires_at: Time.now + $redis.publish job_done.uuid, "end" + @running.delete job_done.uuid end + def update_pipelines + @todo_pipelines.each do |p| + pipe_auth = ApiClientAuthorization. + new(user: User.where('uuid=?', p.modified_by_user_uuid).first, + api_client_id: 0) + pipe_auth.save + + puts `export ARVADOS_API_TOKEN=#{pipe_auth.api_token} && arv-run-pipeline-instance --run-here --no-wait --instance #{p.uuid}` + end + end + def run act_as_system_user @running ||= {} @@ -338,6 +355,9 @@ class Dispatcher unless @todo.empty? or did_recently(:start_jobs, 1.0) or $signal[:term] start_jobs end + unless @todo_pipelines.empty? or did_recently(:update_pipelines, 5.0) + update_pipelines + end end reap_children select(@running.values.collect { |j| [j[:stdout], j[:stderr]] }.flatten,