Move pusher config to main config
This commit is contained in:
parent
f94ff75a13
commit
7650520beb
|
@ -10,12 +10,25 @@ loadConfig = ->
|
||||||
# to allow more granular config later
|
# to allow more granular config later
|
||||||
pro = $('meta[name="travis.pro"]').attr('value') == 'true' || enterprise
|
pro = $('meta[name="travis.pro"]').attr('value') == 'true' || enterprise
|
||||||
|
|
||||||
|
if config.pro
|
||||||
|
pusher =
|
||||||
|
channels: []
|
||||||
|
channel_prefix: 'private-'
|
||||||
|
encrypted: true
|
||||||
|
key: ''
|
||||||
|
else
|
||||||
|
pusher =
|
||||||
|
channels: ['common']
|
||||||
|
channel_prefix: ''
|
||||||
|
encrypted: false
|
||||||
|
|
||||||
return {
|
return {
|
||||||
syncingPageRedirectionTime: 5000
|
syncingPageRedirectionTime: 5000
|
||||||
api_endpoint: $('meta[rel="travis.api_endpoint"]').attr('href')
|
api_endpoint: $('meta[rel="travis.api_endpoint"]').attr('href')
|
||||||
source_endpoint: $('meta[rel="travis.source_endpoint"]').attr('href')
|
source_endpoint: $('meta[rel="travis.source_endpoint"]').attr('href')
|
||||||
pusher_key: $('meta[name="travis.pusher_key"]').attr('value')
|
pusher_key: $('meta[name="travis.pusher_key"]').attr('value')
|
||||||
pusher_host: $('meta[name="travis.pusher_host"]').attr('value')
|
pusher_host: $('meta[name="travis.pusher_host"]').attr('value')
|
||||||
|
pusher_path: $('meta[name="travis.pusher_path"]').attr('value')
|
||||||
ga_code: $('meta[name="travis.ga_code"]').attr('value')
|
ga_code: $('meta[name="travis.ga_code"]').attr('value')
|
||||||
code_climate: $('meta[name="travis.code_climate"]').attr('value')
|
code_climate: $('meta[name="travis.code_climate"]').attr('value')
|
||||||
ssh_key_enabled: $('meta[name="travis.ssh_key_enabled"]').attr('value') == 'true'
|
ssh_key_enabled: $('meta[name="travis.ssh_key_enabled"]').attr('value') == 'true'
|
||||||
|
@ -38,15 +51,19 @@ loadConfig = ->
|
||||||
customer_io_site_id: customer_io_site_id
|
customer_io_site_id: customer_io_site_id
|
||||||
|
|
||||||
intervals: { times: -1, updateTimes: 1000 }
|
intervals: { times: -1, updateTimes: 1000 }
|
||||||
|
pusher: pusher
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize = (container, application) ->
|
initialize = (container, application) ->
|
||||||
application.register 'config:main', application.config, { instantiate: false }
|
config = application.config
|
||||||
|
application.register 'config:main', config, { instantiate: false }
|
||||||
|
|
||||||
application.inject('controller', 'config', 'config:main')
|
application.inject('controller', 'config', 'config:main')
|
||||||
application.inject('route', 'config', 'config:main')
|
application.inject('route', 'config', 'config:main')
|
||||||
application.inject('auth', 'config', 'config:main')
|
application.inject('auth', 'config', 'config:main')
|
||||||
|
|
||||||
|
application.pusher.config = config
|
||||||
|
|
||||||
ConfigInitializer =
|
ConfigInitializer =
|
||||||
name: 'config'
|
name: 'config'
|
||||||
initialize: initialize
|
initialize: initialize
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
require 'routes/route'
|
require 'routes/route'
|
||||||
|
|
||||||
TravisRoute = Travis.Route
|
TravisRoute = Travis.Route
|
||||||
channels = Travis.Pusher.CHANNELS
|
|
||||||
|
|
||||||
Route = TravisRoute.extend
|
Route = TravisRoute.extend
|
||||||
renderTemplate: ->
|
renderTemplate: ->
|
||||||
|
@ -18,7 +17,7 @@ Route = TravisRoute.extend
|
||||||
|
|
||||||
activate: ->
|
activate: ->
|
||||||
# subscribe to pusher only if we're at a main route
|
# subscribe to pusher only if we're at a main route
|
||||||
if channels
|
if @config.pusher.channels
|
||||||
@get('pusher').subscribeAll(channels)
|
@get('pusher').subscribeAll(@config.pusher.channels)
|
||||||
|
|
||||||
Travis.MainRoute = Route
|
Travis.MainRoute = Route
|
||||||
|
|
|
@ -1,117 +1,101 @@
|
||||||
Travis.Pusher = (config) ->
|
TravisPusher = (config) ->
|
||||||
@init(config)
|
@init(config)
|
||||||
this
|
this
|
||||||
|
|
||||||
if Travis.config.pro
|
TravisPusher.prototype.active_channels = []
|
||||||
$.extend Travis.Pusher,
|
|
||||||
CHANNELS: []
|
|
||||||
CHANNEL_PREFIX: 'private-'
|
|
||||||
ENCRYPTED: true
|
|
||||||
KEY: ''
|
|
||||||
else
|
|
||||||
$.extend Travis.Pusher,
|
|
||||||
CHANNELS: ['common']
|
|
||||||
CHANNEL_PREFIX: ''
|
|
||||||
ENCRYPTED: false
|
|
||||||
|
|
||||||
$.extend Travis.Pusher.prototype,
|
TravisPusher.prototype.init = (config) ->
|
||||||
active_channels: []
|
Pusher.warn = @warn.bind(this)
|
||||||
|
Pusher.host = config.host if config.host
|
||||||
|
@pusher = new Pusher(config.key, encrypted: @config.pusher.encrypted, disableStats: true)
|
||||||
|
|
||||||
init: (config) ->
|
@callbacksToProcess = []
|
||||||
Pusher.warn = @warn.bind(this)
|
|
||||||
Pusher.host = config.host if config.host
|
|
||||||
@pusher = new Pusher(config.key, encrypted: Travis.Pusher.ENCRYPTED, disableStats: true)
|
|
||||||
|
|
||||||
@callbacksToProcess = []
|
Visibility.change (e, state) =>
|
||||||
|
@processSavedCallbacks() if state == 'visible'
|
||||||
|
|
||||||
Visibility.change (e, state) =>
|
setInterval @processSavedCallbacks.bind(this), @processingIntervalWhenHidden
|
||||||
@processSavedCallbacks() if state == 'visible'
|
|
||||||
|
|
||||||
setInterval @processSavedCallbacks.bind(this), @processingIntervalWhenHidden
|
TravisPusher.prototype.subscribeAll = (channels) ->
|
||||||
|
@subscribe(channel) for channel in channels
|
||||||
|
|
||||||
subscribeAll: (channels) ->
|
TravisPusher.prototype.unsubscribeAll = (channels) ->
|
||||||
@subscribe(channel) for channel in channels
|
@unsubscribe(channel) for channel in channels
|
||||||
|
|
||||||
unsubscribeAll: (channels) ->
|
TravisPusher.prototype.subscribe = (channel) ->
|
||||||
@unsubscribe(channel) for channel in channels
|
return unless channel
|
||||||
|
channel = @prefix(channel)
|
||||||
|
console.log("subscribing to #{channel}")
|
||||||
|
unless @pusher?.channel(channel)
|
||||||
|
@pusher.subscribe(channel).bind_all((event, data) => @receive(event, data))
|
||||||
|
|
||||||
subscribe: (channel) ->
|
TravisPusher.prototype.unsubscribe = (channel) ->
|
||||||
return unless channel
|
return unless channel
|
||||||
channel = @prefix(channel)
|
channel = @prefix(channel)
|
||||||
console.log("subscribing to #{channel}")
|
console.log("unsubscribing from #{channel}")
|
||||||
unless @pusher?.channel(channel)
|
@pusher.unsubscribe(channel) if @pusher?.channel(channel)
|
||||||
@pusher.subscribe(channel).bind_all((event, data) => @receive(event, data))
|
|
||||||
|
|
||||||
unsubscribe: (channel) ->
|
TravisPusher.prototype.prefix = (channel) ->
|
||||||
return unless channel
|
if channel.indexOf(@config.pusher.channel_prefix) != 0
|
||||||
channel = @prefix(channel)
|
"#{@config.pusher.channel_prefix}#{channel}"
|
||||||
console.log("unsubscribing from #{channel}")
|
else
|
||||||
@pusher.unsubscribe(channel) if @pusher?.channel(channel)
|
channel
|
||||||
|
|
||||||
prefix: (channel) ->
|
# process pusher messages in batches every 5 minutes when the page is hidden
|
||||||
if channel.indexOf(Travis.Pusher.CHANNEL_PREFIX) != 0
|
TravisPusher.prototype.processingIntervalWhenHidden = 1000 * 60 * 5
|
||||||
"#{Travis.Pusher.CHANNEL_PREFIX}#{channel}"
|
|
||||||
else
|
|
||||||
channel
|
|
||||||
|
|
||||||
# process pusher messages in batches every 5 minutes when the page is hidden
|
TravisPusher.prototype.receive = (event, data) ->
|
||||||
processingIntervalWhenHidden: 1000 * 60 * 5
|
return if event.substr(0, 6) == 'pusher'
|
||||||
|
data = @normalize(event, data) if data.id
|
||||||
|
|
||||||
receive: (event, data) ->
|
@processWhenVisible =>
|
||||||
return if event.substr(0, 6) == 'pusher'
|
# TODO remove job:requeued, once sf-restart-event has been merged
|
||||||
data = @normalize(event, data) if data.id
|
# TODO this also needs to clear logs on build:created if matrix jobs are already loaded
|
||||||
|
if event == 'job:created' || event == 'job:requeued'
|
||||||
|
if job = Travis.__container__.lookup('store:main').getById('job', data.job.id)
|
||||||
|
job.clearLog()
|
||||||
|
|
||||||
@processWhenVisible =>
|
Ember.run.next ->
|
||||||
# TODO remove job:requeued, once sf-restart-event has been merged
|
Travis.receive(event, data)
|
||||||
# TODO this also needs to clear logs on build:created if matrix jobs are already loaded
|
|
||||||
if event == 'job:created' || event == 'job:requeued'
|
|
||||||
if job = Travis.__container__.lookup('store:main').getById('job', data.job.id)
|
|
||||||
job.clearLog()
|
|
||||||
|
|
||||||
Ember.run.next ->
|
TravisPusher.prototype.processSavedCallbacks = ->
|
||||||
Travis.receive(event, data)
|
while callback = @callbacksToProcess.shiftObject()
|
||||||
|
callback.call(this)
|
||||||
|
|
||||||
processSavedCallbacks: ->
|
TravisPusher.prototype.processLater = (callback) ->
|
||||||
while callback = @callbacksToProcess.shiftObject()
|
@callbacksToProcess.pushObject(callback)
|
||||||
callback.call(this)
|
|
||||||
|
|
||||||
processLater: (callback) ->
|
TravisPusher.prototype.processWhenVisible = (callback) ->
|
||||||
@callbacksToProcess.pushObject(callback)
|
if Visibility.hidden() && Visibility.isSupported()
|
||||||
|
@processLater(callback)
|
||||||
|
else
|
||||||
|
callback.call(this)
|
||||||
|
|
||||||
processWhenVisible: (callback) ->
|
TravisPusher.prototype.normalize = (event, data) ->
|
||||||
if Visibility.hidden() && Visibility.isSupported()
|
switch event
|
||||||
@processLater(callback)
|
when 'build:started', 'build:finished'
|
||||||
else
|
data
|
||||||
callback.call(this)
|
when 'job:created', 'job:started', 'job:requeued', 'job:finished', 'job:log', 'job:canceled', 'job:received'
|
||||||
|
data.queue = data.queue.replace('builds.', '') if data.queue
|
||||||
|
{ job: data }
|
||||||
|
when 'worker:added', 'worker:updated', 'worker:removed'
|
||||||
|
{ worker: data }
|
||||||
|
when 'annotation:created', 'annotation:updated'
|
||||||
|
{ annotation: data }
|
||||||
|
|
||||||
normalize: (event, data) ->
|
TravisPusher.prototype.warn = (type, object) ->
|
||||||
switch event
|
console.warn(type, object.error) unless @ignoreWarning(type, object.error)
|
||||||
when 'build:started', 'build:finished'
|
|
||||||
data
|
|
||||||
when 'job:created', 'job:started', 'job:requeued', 'job:finished', 'job:log', 'job:canceled', 'job:received'
|
|
||||||
data.queue = data.queue.replace('builds.', '') if data.queue
|
|
||||||
{ job: data }
|
|
||||||
when 'worker:added', 'worker:updated', 'worker:removed'
|
|
||||||
{ worker: data }
|
|
||||||
when 'annotation:created', 'annotation:updated'
|
|
||||||
{ annotation: data }
|
|
||||||
|
|
||||||
warn: (type, object) ->
|
TravisPusher.prototype.ignoreWarning = (type, error) ->
|
||||||
console.warn(type, object.error) unless @ignoreWarning(type, object.error)
|
code = error?.data?.code || 0
|
||||||
|
message = error?.data?.message || ''
|
||||||
|
@ignoreCode(code) || @ignoreMessage(message)
|
||||||
|
|
||||||
ignoreWarning: (type, error) ->
|
TravisPusher.prototype.ignoreCode = (code) ->
|
||||||
code = error?.data?.code || 0
|
code == 1006
|
||||||
message = error?.data?.message || ''
|
|
||||||
@ignoreCode(code) || @ignoreMessage(message)
|
|
||||||
|
|
||||||
ignoreCode: (code) ->
|
TravisPusher.prototype.ignoreMessage = (message) ->
|
||||||
code == 1006
|
message.indexOf('Existing subscription') == 0 or message.indexOf('No current subscription') == 0
|
||||||
|
|
||||||
ignoreMessage: (message) ->
|
|
||||||
message.indexOf('Existing subscription') == 0 or message.indexOf('No current subscription') == 0
|
|
||||||
|
|
||||||
pusher_host = $('meta[name="travis.pusher_host"]').attr('value')
|
|
||||||
pusher_path = $('meta[name="travis.pusher_path"]').attr('value')
|
|
||||||
|
|
||||||
Pusher.SockJSTransport.isSupported = -> false if pusher_host != 'ws.pusherapp.com'
|
Pusher.SockJSTransport.isSupported = -> false if pusher_host != 'ws.pusherapp.com'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user