Merge pull request #384 from travis-ci/remove-visibility-api-from-pusher
Remove Visibility API usage from Pusher
This commit is contained in:
commit
5ad61f1968
|
@ -12,13 +12,6 @@ TravisPusher.prototype.init = (config) ->
|
||||||
Pusher.host = config.host if config.host
|
Pusher.host = config.host if config.host
|
||||||
@pusher = new Pusher(config.key, encrypted: config.encrypted, disableStats: true)
|
@pusher = new Pusher(config.key, encrypted: config.encrypted, disableStats: true)
|
||||||
|
|
||||||
@callbacksToProcess = []
|
|
||||||
|
|
||||||
Visibility.change (e, state) =>
|
|
||||||
@processSavedCallbacks() if state == 'visible'
|
|
||||||
|
|
||||||
setInterval @processSavedCallbacks.bind(this), @processingIntervalWhenHidden
|
|
||||||
|
|
||||||
TravisPusher.prototype.subscribeAll = (channels) ->
|
TravisPusher.prototype.subscribeAll = (channels) ->
|
||||||
@subscribe(channel) for channel in channels
|
@subscribe(channel) for channel in channels
|
||||||
|
|
||||||
|
@ -44,35 +37,18 @@ TravisPusher.prototype.prefix = (channel) ->
|
||||||
else
|
else
|
||||||
channel
|
channel
|
||||||
|
|
||||||
# process pusher messages in batches every 5 minutes when the page is hidden
|
|
||||||
TravisPusher.prototype.processingIntervalWhenHidden = 1000 * 60 * 5
|
|
||||||
|
|
||||||
TravisPusher.prototype.receive = (event, data) ->
|
TravisPusher.prototype.receive = (event, data) ->
|
||||||
return if event.substr(0, 6) == 'pusher'
|
return if event.substr(0, 6) == 'pusher'
|
||||||
data = @normalize(event, data) if data.id
|
data = @normalize(event, data) if data.id
|
||||||
|
|
||||||
@processWhenVisible =>
|
# TODO remove job:requeued, once sf-restart-event has been merged
|
||||||
# TODO remove job:requeued, once sf-restart-event has been merged
|
# TODO this also needs to clear logs on build:created if matrix jobs are already loaded
|
||||||
# TODO this also needs to clear logs on build:created if matrix jobs are already loaded
|
if event == 'job:created' || event == 'job:requeued'
|
||||||
if event == 'job:created' || event == 'job:requeued'
|
if job = @store.getById('job', data.job.id)
|
||||||
if job = @store.getById('job', data.job.id)
|
job.clearLog()
|
||||||
job.clearLog()
|
|
||||||
|
|
||||||
Ember.run.next =>
|
Ember.run.next =>
|
||||||
@store.receivePusherEvent(event, data)
|
@store.receivePusherEvent(event, data)
|
||||||
|
|
||||||
TravisPusher.prototype.processSavedCallbacks = ->
|
|
||||||
while callback = @callbacksToProcess.shiftObject()
|
|
||||||
callback.call(this)
|
|
||||||
|
|
||||||
TravisPusher.prototype.processLater = (callback) ->
|
|
||||||
@callbacksToProcess.pushObject(callback)
|
|
||||||
|
|
||||||
TravisPusher.prototype.processWhenVisible = (callback) ->
|
|
||||||
if Visibility.hidden() && Visibility.isSupported()
|
|
||||||
@processLater(callback)
|
|
||||||
else
|
|
||||||
callback.call(this)
|
|
||||||
|
|
||||||
TravisPusher.prototype.normalize = (event, data) ->
|
TravisPusher.prototype.normalize = (event, data) ->
|
||||||
switch event
|
switch event
|
||||||
|
|
Loading…
Reference in New Issue
Block a user