2012-03-02 18:28:52 +00:00
|
|
|
Flowerbox =
|
2012-03-14 17:07:13 +00:00
|
|
|
debug: false
|
2012-03-13 17:21:32 +00:00
|
|
|
ping: ->
|
|
|
|
Flowerbox.contact('ping')
|
2012-03-15 15:57:35 +00:00
|
|
|
|
2012-03-26 15:31:50 +00:00
|
|
|
messageQueue: []
|
2012-04-12 23:46:03 +00:00
|
|
|
pulling: false
|
2012-03-26 15:31:50 +00:00
|
|
|
|
2012-03-02 18:28:52 +00:00
|
|
|
contact: (url, data...) ->
|
2012-03-21 22:41:29 +00:00
|
|
|
Flowerbox.started = true
|
2012-03-21 22:43:45 +00:00
|
|
|
|
2012-03-14 17:07:13 +00:00
|
|
|
if !Flowerbox.debug
|
2012-03-26 15:31:50 +00:00
|
|
|
message = [ url, data ]
|
|
|
|
Flowerbox.messageQueue.push(message)
|
|
|
|
|
2012-04-12 23:46:03 +00:00
|
|
|
if Flowerbox.socket && !Flowerbox.pulling
|
|
|
|
Flowerbox.queuePuller()
|
2012-03-24 14:17:33 +00:00
|
|
|
|
2012-03-15 15:57:35 +00:00
|
|
|
started: false
|
|
|
|
done: false
|
2012-03-15 00:32:01 +00:00
|
|
|
|
2012-04-09 16:03:54 +00:00
|
|
|
queuePuller: ->
|
2012-04-12 23:46:03 +00:00
|
|
|
Flowerbox.pulling = true
|
|
|
|
|
2012-04-09 16:03:54 +00:00
|
|
|
if Flowerbox.messageQueue.length > 0
|
|
|
|
message = Flowerbox.messageQueue.shift()
|
|
|
|
|
2012-04-12 23:46:03 +00:00
|
|
|
Flowerbox.socket.onmessage = (data) ->
|
2012-04-09 16:03:54 +00:00
|
|
|
if message[0] == 'results'
|
|
|
|
if __$instrument?
|
|
|
|
Flowerbox.socket.send JSON.stringify(['instrument', __$instrument]) {}, ->
|
|
|
|
Flowerbox.done = true
|
|
|
|
else
|
|
|
|
Flowerbox.done = true
|
|
|
|
|
|
|
|
Flowerbox.queuePuller()
|
|
|
|
|
2012-04-12 23:46:03 +00:00
|
|
|
Flowerbox.socket.send JSON.stringify(message)
|
|
|
|
else
|
|
|
|
setTimeout(Flowerbox.queuePuller, 10) if !Flowerbox.done
|
|
|
|
|
2012-03-03 16:28:03 +00:00
|
|
|
fail: ->
|
2012-03-13 17:21:32 +00:00
|
|
|
|
2012-04-11 20:35:29 +00:00
|
|
|
class Flowerbox.Exception
|
|
|
|
constructor: (@source, @name, @stack) ->
|
|
|
|
|
|
|
|
toJSON: ->
|
|
|
|
{ status: Flowerbox.Result.FAILURE, source: @source, name: @name, trace: { stack: @stack } }
|
|
|
|
|
|
|
|
class Flowerbox.Result
|
|
|
|
@SUCCESS = 'success'
|
|
|
|
@PENDING = 'pending'
|
|
|
|
@UNDEFINED = 'undefined'
|
|
|
|
@FAILURE = 'failure'
|
|
|
|
@SKIPPED = 'skipped'
|
|
|
|
|
|
|
|
constructor: (data) ->
|
|
|
|
for key, value of data
|
|
|
|
this[key] = value
|
|
|
|
|
|
|
|
this.status ||= Flowerbox.Result.SKIPPED
|
|
|
|
this.failures ||= []
|
|
|
|
|
|
|
|
toJSON: => this
|
|
|
|
|