Remove incomplete records loading implementation
This commit is contained in:
parent
5c913fcaaa
commit
e84b7b81c5
|
@ -21,7 +21,14 @@ require 'travis/model'
|
||||||
jobs: Ember.hasMany('Travis.Job')
|
jobs: Ember.hasMany('Travis.Job')
|
||||||
|
|
||||||
config: (->
|
config: (->
|
||||||
Travis.Helpers.compact(@get('_config'))
|
console.log('config')
|
||||||
|
if config = @get('_config')
|
||||||
|
Travis.Helpers.compact(config)
|
||||||
|
else
|
||||||
|
return if @get('isFetchingConfig')
|
||||||
|
@set 'isFetchingConfig', true
|
||||||
|
|
||||||
|
@reload()
|
||||||
).property('_config')
|
).property('_config')
|
||||||
|
|
||||||
isPullRequest: (->
|
isPullRequest: (->
|
||||||
|
@ -85,12 +92,6 @@ require 'travis/model'
|
||||||
requeue: ->
|
requeue: ->
|
||||||
Travis.ajax.post "/builds/#{@get('id')}/restart"
|
Travis.ajax.post "/builds/#{@get('id')}/restart"
|
||||||
|
|
||||||
isPropertyLoaded: (key) ->
|
|
||||||
if ['_duration', '_finishedAt'].contains(key) && !@get('isFinished')
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
@_super(key)
|
|
||||||
|
|
||||||
formattedFinishedAt: (->
|
formattedFinishedAt: (->
|
||||||
if finishedAt = @get('finishedAt')
|
if finishedAt = @get('finishedAt')
|
||||||
moment(finishedAt).format('lll')
|
moment(finishedAt).format('lll')
|
||||||
|
|
|
@ -6,11 +6,3 @@ Travis.EnvVar = Travis.Model.extend
|
||||||
public: Ember.attr('boolean')
|
public: Ember.attr('boolean')
|
||||||
|
|
||||||
repo: Ember.belongsTo('Travis.Repo', key: 'repository_id')
|
repo: Ember.belongsTo('Travis.Repo', key: 'repository_id')
|
||||||
|
|
||||||
isPropertyLoaded: (key) ->
|
|
||||||
if key == 'value'
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
@_super(key)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,13 @@ require 'travis/model'
|
||||||
).property('repositorySlug')
|
).property('repositorySlug')
|
||||||
|
|
||||||
config: (->
|
config: (->
|
||||||
Travis.Helpers.compact(@get('_config'))
|
if config = @get('_config')
|
||||||
|
Travis.Helpers.compact(config)
|
||||||
|
else
|
||||||
|
return if @get('isFetchingConfig')
|
||||||
|
@set 'isFetchingConfig', true
|
||||||
|
|
||||||
|
@reload()
|
||||||
).property('_config')
|
).property('_config')
|
||||||
|
|
||||||
isFinished: (->
|
isFinished: (->
|
||||||
|
@ -106,14 +112,6 @@ require 'travis/model'
|
||||||
Travis.pusher.unsubscribe "job-#{@get('id')}"
|
Travis.pusher.unsubscribe "job-#{@get('id')}"
|
||||||
).observes('state')
|
).observes('state')
|
||||||
|
|
||||||
isPropertyLoaded: (key) ->
|
|
||||||
if ['_finishedAt'].contains(key) && !@get('isFinished')
|
|
||||||
return true
|
|
||||||
else if key == '_startedAt' && @get('state') == 'created'
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
@_super(key)
|
|
||||||
|
|
||||||
isFinished: (->
|
isFinished: (->
|
||||||
@get('state') in ['passed', 'failed', 'errored', 'canceled']
|
@get('state') in ['passed', 'failed', 'errored', 'canceled']
|
||||||
).property('state')
|
).property('state')
|
||||||
|
|
|
@ -3,11 +3,3 @@ Travis.SshKey = Travis.Model.extend
|
||||||
value: Ember.attr('string')
|
value: Ember.attr('string')
|
||||||
description: Ember.attr('string')
|
description: Ember.attr('string')
|
||||||
fingerprint: Ember.attr('string')
|
fingerprint: Ember.attr('string')
|
||||||
|
|
||||||
isPropertyLoaded: (key) ->
|
|
||||||
if key == 'value'
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
@_super(key)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,84 +34,19 @@ Array.prototype.diff = (a) ->
|
||||||
|
|
||||||
@_super(key)
|
@_super(key)
|
||||||
|
|
||||||
load: (id, hash) ->
|
|
||||||
@loadedAttributes = []
|
|
||||||
@loadedRelationships = []
|
|
||||||
|
|
||||||
attributes = this.constructor.getAttributes() || []
|
|
||||||
relationships = this.constructor.getRelationships() || []
|
|
||||||
|
|
||||||
if hash
|
|
||||||
for key in attributes
|
|
||||||
dataKey = @dataKey(key)
|
|
||||||
if hash.hasOwnProperty(dataKey)
|
|
||||||
@loadedAttributes.pushObject(key)
|
|
||||||
|
|
||||||
for key in relationships
|
|
||||||
dataKey = @dataKey(key)
|
|
||||||
if hash.hasOwnProperty(dataKey)
|
|
||||||
@loadedRelationships.pushObject(key)
|
|
||||||
|
|
||||||
incomplete = Ember.EnumerableUtils.intersection(@loadedAttributes, attributes).length != attributes.length ||
|
|
||||||
Ember.EnumerableUtils.intersection(@loadedRelationships, relationships).length != relationships.length
|
|
||||||
|
|
||||||
#if incomplete
|
|
||||||
# properties = attributes.concat(relationships)
|
|
||||||
# loadedProperties = @loadedAttributes.concat(@loadedRelationships)
|
|
||||||
# diff = properties.diff(loadedProperties)
|
|
||||||
# #console.log(@constructor, 'with id', id, 'loaded as incomplete, info:', { diff: diff, attributes: loadedProperties, data: hash})
|
|
||||||
|
|
||||||
@set('incomplete', incomplete)
|
|
||||||
|
|
||||||
@_super(id, hash)
|
|
||||||
|
|
||||||
getAttr: (key, options) ->
|
|
||||||
@needsCompletionCheck(key)
|
|
||||||
@_super.apply this, arguments
|
|
||||||
|
|
||||||
getBelongsTo: (key, type, meta) ->
|
getBelongsTo: (key, type, meta) ->
|
||||||
unless key
|
unless key
|
||||||
key = type.singularName() + '_id'
|
key = type.singularName() + '_id'
|
||||||
@needsCompletionCheck(key)
|
|
||||||
@_super(key, type, meta)
|
@_super(key, type, meta)
|
||||||
|
|
||||||
getHasMany: (key, type, meta) ->
|
getHasMany: (key, type, meta) ->
|
||||||
unless key
|
unless key
|
||||||
key = type.singularName() + '_ids'
|
key = type.singularName() + '_ids'
|
||||||
@needsCompletionCheck(key)
|
|
||||||
@_super(key, type, meta)
|
@_super(key, type, meta)
|
||||||
|
|
||||||
needsCompletionCheck: (key) ->
|
|
||||||
if key && (@isAttribute(key) || @isRelationship(key)) &&
|
|
||||||
@get('incomplete') && !@isPropertyLoaded(key)
|
|
||||||
@loadTheRest(key)
|
|
||||||
|
|
||||||
isAttribute: (name) ->
|
|
||||||
this.constructor.getAttributes().contains(name)
|
|
||||||
|
|
||||||
isRelationship: (name) ->
|
|
||||||
this.constructor.getRelationships().contains(name)
|
|
||||||
|
|
||||||
loadTheRest: (key) ->
|
|
||||||
# for some weird reason key comes changed to a string and for some weird reason it even is called with
|
|
||||||
# undefined key
|
|
||||||
return if !key || key == 'undefined'
|
|
||||||
|
|
||||||
message = "Load missing fields for #{@constructor.toString()} because of missing key '#{key}', cid: #{@get('clientId')}, id: #{@get('id')}"
|
|
||||||
if @isAttribute('state') && key != 'state'
|
|
||||||
message += ", in state: #{@get('state')}"
|
|
||||||
console.log message
|
|
||||||
return if @get('isCompleting')
|
|
||||||
@set 'isCompleting', true
|
|
||||||
|
|
||||||
@reload()
|
|
||||||
|
|
||||||
select: ->
|
select: ->
|
||||||
@constructor.select(@get('id'))
|
@constructor.select(@get('id'))
|
||||||
|
|
||||||
isPropertyLoaded: (name) ->
|
|
||||||
@loadedAttributes.contains(name) || @loadedRelationships.contains(name)
|
|
||||||
|
|
||||||
@Travis.Model.reopenClass
|
@Travis.Model.reopenClass
|
||||||
select: (id) ->
|
select: (id) ->
|
||||||
@find().forEach (record) ->
|
@find().forEach (record) ->
|
||||||
|
|
|
@ -6,37 +6,6 @@ module "Travis.Build",
|
||||||
Travis.Build.resetData()
|
Travis.Build.resetData()
|
||||||
Travis.Job.resetData()
|
Travis.Job.resetData()
|
||||||
|
|
||||||
test 'it does not load record on duration, finishedAt and result if job is not in finished state', ->
|
|
||||||
Travis.Build.load [{ id: 1, state: 'started', started_at: null }]
|
|
||||||
|
|
||||||
Ember.run ->
|
|
||||||
record = Travis.Build.find 1
|
|
||||||
|
|
||||||
record.loadTheRest = ->
|
|
||||||
ok(false, 'loadTheRest should not be called')
|
|
||||||
|
|
||||||
record.get('duration')
|
|
||||||
record.get('finishedAt')
|
|
||||||
record.get('result')
|
|
||||||
|
|
||||||
wait().then ->
|
|
||||||
ok(true, 'loadTheRest was not called')
|
|
||||||
|
|
||||||
test 'it loads record on duration, finishedAt and result if job is in finished state', ->
|
|
||||||
expect(1)
|
|
||||||
|
|
||||||
Travis.Build.load [{ id: 1, state: 'passed', started_at: null }]
|
|
||||||
|
|
||||||
Ember.run ->
|
|
||||||
record = Travis.Build.find 1
|
|
||||||
|
|
||||||
record.loadTheRest = ->
|
|
||||||
ok(true, 'loadTheRest should be called')
|
|
||||||
|
|
||||||
record.get('finishedAt')
|
|
||||||
|
|
||||||
wait()
|
|
||||||
|
|
||||||
test 'it takes into account all the jobs when getting config keys', ->
|
test 'it takes into account all the jobs when getting config keys', ->
|
||||||
buildConfig = { rvm: ['1.9.3', '2.0.0'] }
|
buildConfig = { rvm: ['1.9.3', '2.0.0'] }
|
||||||
Travis.Build.load [{ id: '1', job_ids: ['1', '2', '3'], config: buildConfig }]
|
Travis.Build.load [{ id: '1', job_ids: ['1', '2', '3'], config: buildConfig }]
|
||||||
|
|
|
@ -1,83 +0,0 @@
|
||||||
fullPostHash = null
|
|
||||||
Post = null
|
|
||||||
Author = null
|
|
||||||
|
|
||||||
module "Travis.Model - incomplete",
|
|
||||||
setup: ->
|
|
||||||
fullPostHash = {
|
|
||||||
id: '1',
|
|
||||||
title: 'foo',
|
|
||||||
published_at: 'today',
|
|
||||||
|
|
||||||
author_id: '1'
|
|
||||||
}
|
|
||||||
|
|
||||||
Author = Travis.Model.extend()
|
|
||||||
|
|
||||||
Post = Travis.Model.extend(
|
|
||||||
title: Ember.attr('string'),
|
|
||||||
publishedAt: Ember.attr('string', key: 'published_at'),
|
|
||||||
|
|
||||||
author: Ember.belongsTo(Author, { key: 'author_id' })
|
|
||||||
)
|
|
||||||
|
|
||||||
Post.adapter = Ember.FixtureAdapter.create()
|
|
||||||
|
|
||||||
test "record is marked as incomplete if attributes are missing when loading a record", ->
|
|
||||||
Post.load([{ id: '1', title: 'foo' }])
|
|
||||||
|
|
||||||
record = Post.find('1')
|
|
||||||
ok(record.get('incomplete'), 'record should be incomplete')
|
|
||||||
equal(record.get('title'), 'foo', 'attributes should be accessible')
|
|
||||||
|
|
||||||
test "record is marked as complete if missing attributes are loaded", ->
|
|
||||||
Post.load([{ id: '1', title: 'foo' }])
|
|
||||||
|
|
||||||
record = Post.find('1')
|
|
||||||
ok(record.get('incomplete'), 'record should be complete')
|
|
||||||
equal(record.get('title'), 'foo', 'attributes should be accessible')
|
|
||||||
|
|
||||||
record.load('1', fullPostHash)
|
|
||||||
|
|
||||||
ok(!record.get('incomplete'), 'record should be complete')
|
|
||||||
|
|
||||||
test "record is marked as incomplete if belongsTo key is missing", ->
|
|
||||||
delete(fullPostHash.author_id)
|
|
||||||
Post.load([fullPostHash])
|
|
||||||
|
|
||||||
record = Post.find('1')
|
|
||||||
ok(record.get('incomplete'), 'record should be incomplete')
|
|
||||||
|
|
||||||
test "proeperty can be loaded as null, which means that the property is still loaded", ->
|
|
||||||
fullPostHash.author_id = null
|
|
||||||
fullPostHash.title = null
|
|
||||||
|
|
||||||
Post.load([fullPostHash])
|
|
||||||
|
|
||||||
record = Post.find('1')
|
|
||||||
ok(!record.get('incomplete'), 'record should be complete')
|
|
||||||
equal(record.get('title'), null, 'title should be null')
|
|
||||||
|
|
||||||
test "when accessing missing property, record is loaded", ->
|
|
||||||
Post.FIXTURES = [fullPostHash]
|
|
||||||
Post.load([{ id: '1' }])
|
|
||||||
|
|
||||||
record = null
|
|
||||||
Ember.run -> record = Post.find('1')
|
|
||||||
|
|
||||||
ok(record.get('incomplete'), 'record should be incomplete')
|
|
||||||
|
|
||||||
publishedAt = null
|
|
||||||
Ember.run -> publishedAt = record.get('publishedAt')
|
|
||||||
|
|
||||||
ok(!publishedAt, 'publishedAt should be missing')
|
|
||||||
|
|
||||||
stop()
|
|
||||||
setTimeout( ->
|
|
||||||
start()
|
|
||||||
|
|
||||||
Ember.run -> publishedAt = record.get('publishedAt')
|
|
||||||
equal(publishedAt, 'today', 'publishedAt should be loaded')
|
|
||||||
ok(!record.get('incomplete'), 'record should be complete')
|
|
||||||
, 50)
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
|
|
|
@ -36,37 +36,6 @@ test 'configKeys takes into account the keys of other jobs', ->
|
||||||
deepEqual( configValues2, [ '2.0.0', undefined, 'Gemfile.1', undefined ] )
|
deepEqual( configValues2, [ '2.0.0', undefined, 'Gemfile.1', undefined ] )
|
||||||
deepEqual( configValues3, [ '1.9.3', undefined, undefined, 'OpenJDK' ] )
|
deepEqual( configValues3, [ '1.9.3', undefined, undefined, 'OpenJDK' ] )
|
||||||
|
|
||||||
test 'it does not load record on duration, finishedAt and result if job is not in finished state', ->
|
|
||||||
Travis.Job.load [{ id: 1, state: 'started', started_at: null }]
|
|
||||||
|
|
||||||
Ember.run ->
|
|
||||||
record = Travis.Job.find 1
|
|
||||||
|
|
||||||
record.loadTheRest = ->
|
|
||||||
ok(false, 'loadTheRest should not be called')
|
|
||||||
|
|
||||||
record.get('_duration')
|
|
||||||
record.get('finishedAt')
|
|
||||||
record.get('result')
|
|
||||||
|
|
||||||
wait().then ->
|
|
||||||
ok(true, 'loadTheRest was not called')
|
|
||||||
|
|
||||||
test 'it loads record on duration, finishedAt and result if job is in finished state', ->
|
|
||||||
expect(1)
|
|
||||||
|
|
||||||
Travis.Job.load [{ id: 1, state: 'passed', started_at: null }]
|
|
||||||
|
|
||||||
Ember.run ->
|
|
||||||
record = Travis.Job.find 1
|
|
||||||
|
|
||||||
record.loadTheRest = ->
|
|
||||||
ok(true, 'loadTheRest should be called')
|
|
||||||
|
|
||||||
record.get('finishedAt')
|
|
||||||
|
|
||||||
wait()
|
|
||||||
|
|
||||||
test 'returns config values for all keys available on build with different number of config keys in sibling jobs', ->
|
test 'returns config values for all keys available on build with different number of config keys in sibling jobs', ->
|
||||||
buildAttrs =
|
buildAttrs =
|
||||||
id: 1
|
id: 1
|
||||||
|
|
|
@ -6,12 +6,13 @@ test "it doesn't trigger downloading missing parts if they come in timely fashio
|
||||||
|
|
||||||
callback = -> ok false, 'callback should not be called'
|
callback = -> ok false, 'callback should not be called'
|
||||||
|
|
||||||
chunks = Travis.LogChunks.create(timeout: 15, missingPartsCallback: callback, content: [])
|
chunks = Travis.LogChunks.create(timeout: 20, missingPartsCallback: callback, content: [])
|
||||||
|
|
||||||
setTimeout (-> chunks.pushObject(number: 1, final: false)), 10
|
Ember.run.later (-> chunks.pushObject(number: 1, final: false)), 10
|
||||||
setTimeout (-> chunks.pushObject(number: 2, final: false)), 20
|
Ember.run.later (-> chunks.pushObject(number: 2, final: false)), 20
|
||||||
setTimeout ->
|
setTimeout ->
|
||||||
ok true
|
ok true
|
||||||
|
Ember.run ->
|
||||||
chunks.pushObject(number: 3, final: true)
|
chunks.pushObject(number: 3, final: true)
|
||||||
start()
|
start()
|
||||||
|
|
||||||
|
@ -25,11 +26,11 @@ test "it triggers downloading missing parts if there is a missing part, even tho
|
||||||
callback = (missingNumbers) ->
|
callback = (missingNumbers) ->
|
||||||
deepEqual(missingNumbers, [2, 3], 'callback should be called with missing numbers')
|
deepEqual(missingNumbers, [2, 3], 'callback should be called with missing numbers')
|
||||||
|
|
||||||
chunks = Travis.LogChunks.create(timeout: 15, missingPartsCallback: callback, content: [])
|
chunks = Travis.LogChunks.create(timeout: 20, missingPartsCallback: callback, content: [])
|
||||||
|
|
||||||
chunks.pushObject(number: 1, final: false)
|
Ember.run -> chunks.pushObject(number: 1, final: false)
|
||||||
setTimeout ->
|
setTimeout ->
|
||||||
chunks.pushObject(number: 4, final: true)
|
Ember.run -> chunks.pushObject(number: 4, final: true)
|
||||||
|
|
||||||
ok(!chunks.get('finalized'), "log shouldn't be finalized")
|
ok(!chunks.get('finalized'), "log shouldn't be finalized")
|
||||||
, 10
|
, 10
|
||||||
|
@ -37,7 +38,7 @@ test "it triggers downloading missing parts if there is a missing part, even tho
|
||||||
setTimeout ->
|
setTimeout ->
|
||||||
Ember.run -> chunks.destroy() # destroy object to not fire more callbacks
|
Ember.run -> chunks.destroy() # destroy object to not fire more callbacks
|
||||||
start()
|
start()
|
||||||
, 40
|
, 60
|
||||||
|
|
||||||
test "it triggers downloading next parts if there is no final part", ->
|
test "it triggers downloading next parts if there is no final part", ->
|
||||||
expect(2)
|
expect(2)
|
||||||
|
@ -49,6 +50,7 @@ test "it triggers downloading next parts if there is no final part", ->
|
||||||
|
|
||||||
chunks = Travis.LogChunks.create(timeout: 15, missingPartsCallback: callback, content: [])
|
chunks = Travis.LogChunks.create(timeout: 15, missingPartsCallback: callback, content: [])
|
||||||
|
|
||||||
|
Ember.run ->
|
||||||
chunks.pushObject(number: 1, final: false)
|
chunks.pushObject(number: 1, final: false)
|
||||||
chunks.pushObject(number: 3, final: false)
|
chunks.pushObject(number: 3, final: false)
|
||||||
|
|
||||||
|
@ -58,7 +60,7 @@ test "it triggers downloading next parts if there is no final part", ->
|
||||||
, 35
|
, 35
|
||||||
|
|
||||||
test "it triggers downloading all available parts if there is no parts yet", ->
|
test "it triggers downloading all available parts if there is no parts yet", ->
|
||||||
expect(1)
|
expect(2)
|
||||||
stop()
|
stop()
|
||||||
|
|
||||||
callback = (missingNumbers, after) ->
|
callback = (missingNumbers, after) ->
|
||||||
|
|
Loading…
Reference in New Issue
Block a user