Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit 75a2310

Browse files
committed
closes #21 #22
1 parent a99ab14 commit 75a2310

File tree

3 files changed

+21
-32
lines changed

3 files changed

+21
-32
lines changed

lib/hyper-operation/server_op.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'net/http' unless RUBY_ENGINE == 'opal'
2+
13
module Hyperloop
24
class ServerOp < Operation
35

lib/hyper-operation/transport/connection.rb

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
11
module Hyperloop
22
module AutoCreate
3+
def table_exists?
4+
# works with both rails 4 and 5 without deprecation warnings
5+
if connection.respond_to?(:data_sources)
6+
connection.data_sources.include?(table_name)
7+
else
8+
connection.tables.include?(table_name)
9+
end
10+
end
11+
312
def needs_init?
4-
return false if Hyperloop.transport == :none
5-
return true if connection.respond_to?(:data_sources) && !connection.data_sources.include?(table_name)
6-
return true if !connection.respond_to?(:data_sources) && !connection.tables.include?(table_name)
7-
Hyperloop.on_server?
8-
# the above line appears equivilent to the following two original lines
9-
# the only
10-
# return false unless Hyperloop.on_server?
11-
# return true if defined?(Rails::Server)
12-
# the following lines appeared to be unreachable but perhaps because on_server uses Rails.const_defined? it has some
13-
# subtle difference.
14-
# return true unless Connection.root_path
15-
# uri = URI("#{Connection.root_path}server_up")
16-
# http = Net::HTTP.new(uri.host, uri.port)
17-
# request = Net::HTTP::Get.new(uri.path)
18-
# if uri.scheme == 'https'
19-
# http.use_ssl = true
20-
# http.verify_mode = OpenSSL::SSL::VERIFY_NONE
21-
# end
22-
# http.request(request) && return rescue true
13+
Hyperloop.transport != :none && Hyperloop.on_server? && !table_exists?
2314
end
2415

2516
def create_table(*args, &block)
@@ -111,6 +102,10 @@ class << self
111102
attr_accessor :transport
112103

113104
def active
105+
# if table doesn't exist then we are either calling from within
106+
# a migration or from a console before the server has ever started
107+
# in these cases there are no channels so we return nothing
108+
return [] unless table_exists?
114109
if Hyperloop.on_server?
115110
expired.delete_all
116111
refresh_connections if needs_refresh?
@@ -158,9 +153,10 @@ def root_path=(path)
158153
end
159154

160155
def root_path
161-
QueuedMessage.root_path
162-
rescue
163-
nil
156+
# if the QueuedMessage table doesn't exist then we are either calling from within
157+
# a migration or from a console before the server has ever started
158+
# in these cases there is no root path to the server
159+
QueuedMessage.root_path if QueuedMessage.table_exists?
164160
end
165161

166162
def refresh_connections

lib/hyper-operation/transport/hyperloop.rb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,7 @@ def self.send_data(channel, data)
122122
end
123123

124124
def self.on_server?
125-
return !Rails.const_defined?('Console')
126-
if !Rails.const_defined?('Console') || Rails.const_defined?('Puma') || Rails.const_defined?('Unicorn') || Rails.const_defined?('Server')
127-
true
128-
elsif Rails.const_defined?('Console')
129-
false
130-
else
131-
Rails.logger.warn "Warning: You may encounter performance problems, because your server is currently not known.\n" +
132-
'Please open a server support ticket at http://github.com/ruby-hyperloop/hyper-operation.'
133-
false
134-
end
125+
return defined? Rails::Server
135126
end
136127

137128
def self.pusher

0 commit comments

Comments
 (0)