1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-12 23:09:03 +01:00
fab-manager/app/workers/version_check_worker.rb
Sylvain de9c224a92 improved version check
- use referer from client when available
- save uuid returned by hub
- send uuid to hub on version check
- check the version on each startup to prevent wrong sync
- also: do not save a setting on API update if it has not changed
2020-04-07 17:53:19 +02:00

36 lines
971 B
Ruby

# frozen_string_literal: true
# Will check the application version to ensure it is up-to-date
class VersionCheckWorker
include Sidekiq::Worker
def perform
require 'fab_hub'
res = FabHub.fab_manager_version_check
setting_ver = Setting.find_or_initialize_by(name: 'hub_last_version')
value = {
security: res['status']['security'],
up_to_date: res['status']['up_to_date']
}
if res['upgrade_to']
value['version'] = res['upgrade_to']['semver']
value['url'] = res['upgrade_to']['url']
end
setting_ver.value = value.to_json.to_s
setting_ver.save!
setting_key = Setting.find_or_initialize_by(name: 'hub_public_key')
if setting_key.value != res['key']
setting_key.value = res['key']
setting_key.save!
end
setting_uuid = Setting.find_or_initialize_by(name: 'uuid')
return if setting_uuid.value == res['uuid']
setting_uuid.value = res['uuid']
setting_uuid.save!
end
end