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
|
2020-06-09 18:51:57 +02:00
|
|
|
sidekiq_options lock: :until_executed,
|
|
|
|
on_conflict: :reject,
|
|
|
|
queue: :system
|
2020-01-13 17:05:53 +01:00
|
|
|
|
|
|
|
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?
|
2020-06-09 18:51:57 +02:00
|
|
|
logger.warn "Unable to check the version, maybe FabHub is not running: #{e}"
|
2020-05-12 16:20:46 +02:00
|
|
|
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
|