Story #7658

Updated by Peter Amstutz over 7 years ago

In order to start having long-running tasks that rely on websockets events to trigger state changes, we need to ensure that the Python websockets client will automatically reconnect when there is an unexpected disconnect. 

 Suggested implementation: 

 # Create a new WebsocketEventClient class that doesn't inherit from WebSocketClient 
 # WebsocketEventClient takes @on_event@ in the constructor and has the following public API: @subscribe()@, @unsubscribe()@, @close()@ 
 # The current EventClient class becomes an internal class (_EventClient) 
 # Add a @on_closed()@ callback to _EventClient. 
 # WebsocketEventClient creates an instance of _EventClient and sets callbacks on_event() and on_closed() to itself 
 # When subscribe() and unsubscribe() are called WebsocketEventClient, record in an array and then forward to _EventClient 
 # When events are called from _EventClient, record the sequence number "id" in last_log_id and forward them to the real on_event() handler. 
 # If close() is called by user, set a flag 
 # If on_closed() event is called on WebsocketEventClient, but close flag is false, disconnect from old EventClient object, create a new _EventClient object, and replay the subscriptions with last_log_id set