You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
module Api::V1
class TestController < ApiController
include ActionController::Live
def ticker
response.headers['Content-Type'] = 'text/event-stream'
sse = Ticker::SSE.new(response.stream)
begin
loop do
test = Test.desc
a = test.second.as_json(except: ["created_at", "updated_at", "_id"])
b = test.first.as_json(except: ["created_at", "updated_at", "_id"])
diff = JsonDiff.generate(a, b)
patch = Hana::Patch.new [diff]
#what to do then with `patch.apply` and `sse.write`?
sse.write(json)
end
rescue IOError
logger.info 'Client disconnects causes IOError on write'
ensure
sse.close
end
end
end
end
In app/lib/ticker/sse.rb
module Ticker
class SSE
def initialize(io)
@io = io
end
def write(object, options = {})
options.each do |k,v|
@io.write("#{k}: #{v}\n")
end
@io.write("data: #{JSON.dump(object)}\n\n")
end
def close
@io.close
end
end
end
Many thanks,
The text was updated successfully, but these errors were encountered:
Hi @tenderlove ,
In the controller:
In
app/lib/ticker/sse.rb
Many thanks,
The text was updated successfully, but these errors were encountered: