From e1e4dd922cc2d2bc9890222cc3aeffce7a00fcda Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Mon, 18 Nov 2013 11:53:00 -0800 Subject: [PATCH] Move @redis.exists and .getrange outside .subscribe block. Otherwise they fail silently and the client does not get any of the buffered log messages. --- .../controllers/arvados/v1/jobs_controller.rb | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/services/api/app/controllers/arvados/v1/jobs_controller.rb b/services/api/app/controllers/arvados/v1/jobs_controller.rb index 5d527d3f00..1b2f941805 100644 --- a/services/api/app/controllers/arvados/v1/jobs_controller.rb +++ b/services/api/app/controllers/arvados/v1/jobs_controller.rb @@ -85,20 +85,19 @@ class Arvados::V1::JobsController < ApplicationController end end @redis = Redis.new(:timeout => 0) - @redis.subscribe(@job.uuid) do |event| - if @redis.exists @job.uuid - # A log buffer exists. Start by showing the last few KB. - @redis. - getrange(@job.uuid, 0 - [@opts[:buffer_size], 1].max, -1). - sub(/^[^\n]*\n?/, ''). - split("\n"). - each do |line| - yield "#{line}\n" - end + if @redis.exists @job.uuid + # A log buffer exists. Start by showing the last few KB. + @redis. + getrange(@job.uuid, 0 - [@opts[:buffer_size], 1].max, -1). + sub(/^[^\n]*\n?/, ''). + split("\n"). + each do |line| + yield "#{line}\n" end - # TODO: avoid duplicating the last few lines of the log - # file. Use the fact that timestamps are lexicographically - # ordered. + end + # TODO: avoid missing log entries between getrange() above and + # subscribe() below. + @redis.subscribe(@job.uuid) do |event| event.message do |channel, msg| if msg == "end" @redis.unsubscribe @job.uuid -- 2.30.2