Improve documentation in Runner::Connection
This commit is contained in:
@ -31,18 +31,21 @@ class Runner::Connection
|
|||||||
@exit_code = 1
|
@exit_code = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Register a callback based on the WebSocket connection state
|
||||||
def on(event, &block)
|
def on(event, &block)
|
||||||
return unless EVENTS.include? event
|
return unless EVENTS.include? event
|
||||||
|
|
||||||
instance_variable_set(:"@#{event}_callback", block)
|
instance_variable_set(:"@#{event}_callback", block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Send arbitrary data in the WebSocket connection
|
||||||
def send(raw_data)
|
def send(raw_data)
|
||||||
encoded_message = encode(raw_data)
|
encoded_message = encode(raw_data)
|
||||||
Rails.logger.debug { "#{Time.zone.now.getutc}: Sending to #{@socket.url}: #{encoded_message.inspect}" }
|
Rails.logger.debug { "#{Time.zone.now.getutc}: Sending to #{@socket.url}: #{encoded_message.inspect}" }
|
||||||
@socket.send(encoded_message)
|
@socket.send(encoded_message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Close the WebSocket connection
|
||||||
def close(status)
|
def close(status)
|
||||||
return unless active?
|
return unless active?
|
||||||
|
|
||||||
@ -50,6 +53,7 @@ class Runner::Connection
|
|||||||
@socket.close
|
@socket.close
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Check if the WebSocket connection is currently established
|
||||||
def active?
|
def active?
|
||||||
@status == :established
|
@status == :established
|
||||||
end
|
end
|
||||||
@ -64,6 +68,10 @@ class Runner::Connection
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# === WebSocket Callbacks
|
||||||
|
# These callbacks are executed based on events indicated by Faye WebSockets and are
|
||||||
|
# independent of the JSON specification that is used within the WebSocket once established.
|
||||||
|
|
||||||
def on_message(raw_event)
|
def on_message(raw_event)
|
||||||
Rails.logger.debug { "#{Time.zone.now.getutc}: Receiving from #{@socket.url}: #{raw_event.data.inspect}" }
|
Rails.logger.debug { "#{Time.zone.now.getutc}: Receiving from #{@socket.url}: #{raw_event.data.inspect}" }
|
||||||
event = decode(raw_event)
|
event = decode(raw_event)
|
||||||
@ -101,6 +109,14 @@ class Runner::Connection
|
|||||||
@event_loop.stop
|
@event_loop.stop
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# === Message Handlers
|
||||||
|
# Each message type indicated by the +type+ attribute in the JSON
|
||||||
|
# sent be the runner management has a dedicated method.
|
||||||
|
# Context:: All registered handlers are executed in the scope of
|
||||||
|
# the bindings they had where they were registered.
|
||||||
|
# Information not stored in the binding, such as the
|
||||||
|
# locale or call stack are not available during execution!
|
||||||
|
|
||||||
def handle_exit(event)
|
def handle_exit(event)
|
||||||
@status = :terminated_by_management
|
@status = :terminated_by_management
|
||||||
@exit_code = event[:data]
|
@exit_code = event[:data]
|
||||||
|
Reference in New Issue
Block a user