From a3b67a433b4923468e4d05ba6b143d82b8c2a99d Mon Sep 17 00:00:00 2001 From: Jan Kessler Date: Tue, 9 Apr 2024 12:57:06 +0200 Subject: [PATCH] add server bbb_version to Redis model and adapt poll/servers/status rake tasks --- app/models/server.rb | 6 +++++- lib/tasks/poll.rake | 4 ++-- lib/tasks/servers.rake | 1 + lib/tasks/status.rake | 5 +++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/models/server.rb b/app/models/server.rb index 2e80d503..75ba0ab2 100644 --- a/app/models/server.rb +++ b/app/models/server.rb @@ -2,7 +2,7 @@ class Server < ApplicationRedisRecord define_attribute_methods :id, :url, :secret, :tag, :enabled, :load, :online, :load_multiplier, :healthy_counter, - :unhealthy_counter, :state, :meetings, :users, :largest_meeting, :videos + :unhealthy_counter, :state, :meetings, :users, :largest_meeting, :videos, :bbb_version # Unique ID for this server application_redis_attr :id @@ -49,6 +49,9 @@ class Server < ApplicationRedisRecord # Indicator of total video streams in this server application_redis_attr :videos + # Indicator of the BBB version of this server + application_redis_attr :bbb_version + def online=(value) value = !!value online_will_change! unless @online == value @@ -104,6 +107,7 @@ def save! pipeline.hset(server_key, 'users', users) if users_changed? pipeline.hset(server_key, 'largest_meeting', largest_meeting) if largest_meeting_changed? pipeline.hset(server_key, 'videos', videos) if videos_changed? + pipeline.hset(server_key, 'bbb_version', bbb_version) if bbb_version_changed? pipeline.sadd?('servers', id) if id_changed? state.present? ? save_with_state(pipeline) : save_without_state(pipeline) end diff --git a/lib/tasks/poll.rake b/lib/tasks/poll.rake index a72a91c0..41e4d74a 100644 --- a/lib/tasks/poll.rake +++ b/lib/tasks/poll.rake @@ -183,8 +183,8 @@ namespace :poll do tasks = Server.all.map do |server| Concurrent::Promises.future_on(pool) do Rails.logger.debug { "Checking Version of id=#{server.id}" } - version = get_post_req(encode_bbb_uri('', server.url, server.secret)).xpath('/response/bbbVersion').text - puts version + bbb_version = get_post_req(encode_bbb_uri('', server.url, server.secret)).xpath('/response/bbbVersion').text + server.bbb_version = bbb_version rescue StandardError => e Rails.logger.warn("Unexpected error when checking version of server id=#{server.id}: #{e}") ensure diff --git a/lib/tasks/servers.rake b/lib/tasks/servers.rake index 949de4ca..f5f34098 100644 --- a/lib/tasks/servers.rake +++ b/lib/tasks/servers.rake @@ -15,6 +15,7 @@ task servers: :environment do end puts("\tload: #{server.load.presence || 'unavailable'}") puts("\tload multiplier: #{server.load_multiplier.nil? ? 1.0 : server.load_multiplier.to_d}") + puts("\tbbb version: #{server.bbb_version.nil? ? '' : server.bbb_version}") puts("\ttag: #{server.tag.nil? ? '' : server.tag}") puts("\t#{server.online ? 'online' : 'offline'}") end diff --git a/lib/tasks/status.rake b/lib/tasks/status.rake index 046ebdd1..98328dea 100644 --- a/lib/tasks/status.rake +++ b/lib/tasks/status.rake @@ -7,7 +7,7 @@ task status: :environment do include ApiHelper servers_info = [] - ServerInfo = Struct.new(:hostname, :state, :status, :meetings, :users, :largest, :videos, :load, :tag) + ServerInfo = Struct.new(:hostname, :state, :status, :meetings, :users, :largest, :videos, :load, :bbb_version, :tag) Server.all.each do |server| state = server.state @@ -15,7 +15,7 @@ task status: :environment do state = server.state.present? ? status_with_state(state) : status_without_state(enabled) info = ServerInfo.new(URI.parse(server.url).host, state, server.online ? 'online' : 'offline', server.meetings, server.users, -server.largest_meeting, server.videos, server.load, server.tag) +server.largest_meeting, server.videos, server.load, server.bbb_version, server.tag) # Convert to openstruct to allow dot syntax usage servers_info.push(info) @@ -33,6 +33,7 @@ server.largest_meeting, server.videos, server.load, server.tag) t.add_column('LARGEST MEETING', &:largest) t.add_column('VIDEOS', &:videos) t.add_column('LOAD', &:load) + t.add_column('BBB VERSION', &:bbb_version) t.add_column('TAG', &:tag) end