From 9df79d6944751dd0f7f8ca9b050d0048c5f727d9 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 29 Jan 2013 15:34:58 +0100 Subject: [PATCH] Wait for job.id in Travis.Artifact --- assets/scripts/app/models/artifact.coffee | 38 +++++++++++++---------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/assets/scripts/app/models/artifact.coffee b/assets/scripts/app/models/artifact.coffee index ed0fbb95..e0e7ce40 100644 --- a/assets/scripts/app/models/artifact.coffee +++ b/assets/scripts/app/models/artifact.coffee @@ -8,6 +8,7 @@ require 'travis/model' init: -> @_super.apply this, arguments + @addObserver 'job.id', @fetchBody @fetchBody() @set 'queue', Ember.A([]) @@ -21,25 +22,28 @@ require 'travis/model' @incrementProperty('version') fetchBody: -> - self = this - Travis.ajax.ajax "/jobs/#{@get('job.id')}/log.txt?cors_hax=true", 'GET', - dataType: 'text' - contentType: 'text/plain' - success: (data, textStatus, xhr) -> - if xhr.status == 204 - logUrl = xhr.getResponseHeader('X-Log-Location') + if jobId = @get('job.id') + @removeObserver 'job.id', @fetchBody - # For some reason not all browsers can fetch this header - unless logUrl - logUrl = self.s3Url("/jobs/#{self.get('job.id')}/log.txt") + self = this + Travis.ajax.ajax "/jobs/#{jobId}/log.txt?cors_hax=true", 'GET', + dataType: 'text' + contentType: 'text/plain' + success: (data, textStatus, xhr) -> + if xhr.status == 204 + logUrl = xhr.getResponseHeader('X-Log-Location') - $.ajax - url: logUrl - type: 'GET' - success: (data) -> - self.fetchedBody(data) - else - self.fetchedBody(data) + # For some reason not all browsers can fetch this header + unless logUrl + logUrl = self.s3Url("/jobs/#{jobId}/log.txt") + + $.ajax + url: logUrl + type: 'GET' + success: (data) -> + self.fetchedBody(data) + else + self.fetchedBody(data) s3Url: (path) -> endpoint = Travis.config.api_endpoint