2020-01-13 17:05:53 +01:00
|
|
|
# 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'
|
2020-05-12 16:20:46 +02:00
|
|
|
begin
|
|
|
|
res = FabHub.fab_manager_version_check
|
|
|
|
rescue Errno::ECONNREFUSED => e
|
|
|
|
if Rails.env.development?
|
|
|
|
puts "Unable to check the version, maybe FabHub is not running: #{e}"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-13 17:05:53 +01:00
|
|
|
|
|
|
|
setting_ver = Setting.find_or_initialize_by(name: 'hub_last_version')
|
2020-01-14 16:16:25 +01:00
|
|
|
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
|
2020-01-13 17:05:53 +01:00
|
|
|
setting_ver.save!
|
|
|
|
|
|
|
|
setting_key = Setting.find_or_initialize_by(name: 'hub_public_key')
|
2020-04-07 17:53:19 +02:00
|
|
|
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']
|
2020-01-14 17:59:30 +01:00
|
|
|
|
2020-04-07 17:53:19 +02:00
|
|
|
setting_uuid.value = res['uuid']
|
|
|
|
setting_uuid.save!
|
2020-01-13 17:05:53 +01:00
|
|
|
end
|
|
|
|
end
|