Reputation: 49
Hi everybody, I want to use binance websocket and show in view with ActionCable. I created file `lib/ticker.rb` as below:
require 'faye/websocket'
require 'eventmachine'
require 'json'
Faye::WebSocket.load_adapter('thin')
EM.run do
ws = Faye::WebSocket::Client.new("wss://stream.binance.com:9443/stream?streams=ethusdt@ticker/btcusdt@ticker")
ws.on :message do |event|
response = JSON.parse(event.data)
if response['stream'].split("@")[1] == 'ticker' && response['data']['s'][-4..-1] == 'USDT')
ActionCable.server.broadcast 'ticker_channel', stream: response['stream'], content: response['data']
end
end
end
Then I created systemctl to run it as below:
[Unit]
Description=Thin Binance Ticker
After=syslog.target network.target
[Service]
Type=simple
WorkingDirectory=/usr/share/nginx/html/myproject
ExecStart=/usr/local/rvm/gems/ruby-2.6.5/wrappers/bundle exec thin start -R lib/ticker.rb -p 9292
User=root
Group=root
RestartSec=1
Restart=always
[Install]
WantedBy=multi-user.target
But after a few days of starting it, the ActionCable does not work but the systemctl status is active! I have to restart the systemctl manually, to work ActionCable again. Anyone have an idea?
Upvotes: 0
Views: 137