merge websocket-gateway changes
from promised branch get the changes on router file and apply on develop branch
This commit is contained in:
parent
4144d6d123
commit
52c8b48d81
|
|
@ -95,8 +95,7 @@ module JamWebsockets
|
|||
|
||||
# this thread runs forever while WSG runs, and should do anything easily gotten out of critical message handling path
|
||||
@background_thread = Thread.new {
|
||||
client_check_count = 0
|
||||
user_last_seen_count = 0
|
||||
count = 0
|
||||
|
||||
while true
|
||||
|
||||
|
|
@ -104,17 +103,11 @@ module JamWebsockets
|
|||
periodical_check_connections
|
||||
periodical_notification_seen
|
||||
|
||||
if client_check_count == 30
|
||||
if count == 30
|
||||
periodical_check_clients
|
||||
client_check_count = 0
|
||||
count = 0
|
||||
end
|
||||
client_check_count = client_check_count + 1
|
||||
|
||||
if user_last_seen_count == 120
|
||||
periodical_update_user_last_seen
|
||||
user_last_seen_count = 0
|
||||
end
|
||||
user_last_seen_count = user_last_seen_count + 1
|
||||
count = count + 1
|
||||
|
||||
rescue => e
|
||||
@log.error "unhandled error in thread #{e}"
|
||||
|
|
@ -790,6 +783,7 @@ module JamWebsockets
|
|||
end
|
||||
|
||||
def handle_login(client, options, override_ip = nil, connecting = true)
|
||||
puts("====handle_login====", options)
|
||||
username = options["username"]
|
||||
password = options["password"]
|
||||
token = options["token"]
|
||||
|
|
@ -798,6 +792,8 @@ module JamWebsockets
|
|||
client_type = options["client_type"]
|
||||
machine_fingerprint = options["machine"]
|
||||
os = options["os"]
|
||||
product = options["product"].nil? ? JamRuby::ArtifactUpdate::CLIENT_PREFIX : options['
|
||||
product']
|
||||
udp_reachable = options["udp_reachable"].nil? ? true : options["udp_reachable"] == 'true'
|
||||
jamblaster_serial_no = options["jamblaster_serial_no"]
|
||||
ipv4_link_local = options["ipv4_link_local"]
|
||||
|
|
@ -1001,9 +997,13 @@ module JamWebsockets
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
puts "========================="
|
||||
puts "O/S = #{os}"
|
||||
puts "========================="
|
||||
# if we have OS data, try to grab client update data and let the client have it
|
||||
update = ArtifactUpdate.find_client_by_os(os) if client_type == Connection::TYPE_CLIENT && os
|
||||
update = ArtifactUpdate.find_client_by_os(product, os) if client_type == Connection:
|
||||
:TYPE_CLIENT && os
|
||||
|
||||
client_update = update.update_data if update
|
||||
|
||||
|
|
@ -1053,7 +1053,8 @@ module JamWebsockets
|
|||
end
|
||||
end
|
||||
# if we have OS data, try to grab client update data and let the client have it
|
||||
update = ArtifactUpdate.find_client_by_os(os) if client_type == Connection::TYPE_CLIENT && os
|
||||
update = ArtifactUpdate.find_client_by_os(product, os) if client_type == Connection:
|
||||
:TYPE_CLIENT && os
|
||||
|
||||
client_update = update.update_data if update
|
||||
|
||||
|
|
@ -1536,6 +1537,21 @@ module JamWebsockets
|
|||
end
|
||||
end
|
||||
|
||||
def periodical_update_user_last_seen
|
||||
active_users_ids = @client_lookup.map { |client_id, client_context| client_context.active ? client_context.user.id : nil }.compact.uniq
|
||||
|
||||
if active_users_ids.any?
|
||||
sql = %{
|
||||
update users set last_jam_updated_at = now(), last_jam_updated_reason='#{User::JAM_REASON_PRESENT}' where users.id in (#{active_users_ids.map{|id| "'#{id}'"}.join(',')});
|
||||
}
|
||||
@log.info("SQL #{sql}")
|
||||
|
||||
ConnectionManager.active_record_transaction do |connection_manager, conn|
|
||||
conn.exec(sql)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def periodical_stats_dump
|
||||
|
||||
# assume 60 seconds per status dump
|
||||
|
|
|
|||
Loading…
Reference in New Issue