20850: Fix test selector
[arvados.git] / services / api / config / initializers / eventbus.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 if ENV['ARVADOS_WEBSOCKETS']
6   Server::Application.configure do
7     Rails.logger.error "Built-in websocket server is disabled. See note (2017-03-23, e8cc0d7) at https://dev.arvados.org/projects/arvados/wiki/Upgrading_to_master"
8
9     class EventBusRemoved
10       def overloaded?
11         false
12       end
13       def on_connect ws
14         ws.on :open do |e|
15           EM::Timer.new 1 do
16             ws.send(SafeJSON.dump({status: 501, message: "Server misconfigured? see http://doc.arvados.org/install/install-ws.html"}))
17           end
18           EM::Timer.new 3 do
19             ws.close
20           end
21         end
22       end
23     end
24
25     config.middleware.insert_after(ArvadosApiToken, RackSocket, {
26                                      handler: EventBusRemoved,
27                                      mount: "/websocket",
28                                      websocket_only: (ENV['ARVADOS_WEBSOCKETS'] == "ws-only")
29                                    })
30   end
31 end