2019-01-31 12:19:50 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-03-04 10:35:00 +01:00
|
|
|
# retrieve the Fab-manager's versions
|
2019-01-31 12:19:50 +01:00
|
|
|
class Version
|
2020-03-04 10:35:00 +01:00
|
|
|
# currently installed
|
2019-01-31 12:19:50 +01:00
|
|
|
def self.current
|
|
|
|
package = File.read('package.json')
|
|
|
|
JSON.parse(package)['version']
|
|
|
|
end
|
2020-01-14 14:33:00 +01:00
|
|
|
|
2020-03-04 10:35:00 +01:00
|
|
|
# currently published
|
2020-01-14 14:33:00 +01:00
|
|
|
def self.up_to_date?
|
|
|
|
hub_version = Setting.find_by(name: 'hub_last_version')&.value
|
|
|
|
return unless hub_version
|
|
|
|
|
|
|
|
json = JSON.parse(hub_version)
|
2020-01-14 17:12:36 +01:00
|
|
|
json['up_to_date']
|
2020-01-14 14:33:00 +01:00
|
|
|
end
|
|
|
|
|
2020-03-04 10:35:00 +01:00
|
|
|
# periodically retrieve the last published version from the hub and save it into the database
|
2020-01-14 14:33:00 +01:00
|
|
|
def self.check_and_schedule
|
2020-03-04 10:35:00 +01:00
|
|
|
job_name = 'Automatic version check'
|
2020-01-15 10:46:04 +01:00
|
|
|
return if (Rails.env.development? || Rails.env.test?) && ENV['FORCE_VERSION_CHECK'] != 'true'
|
2020-01-14 17:59:30 +01:00
|
|
|
|
2020-03-04 10:35:00 +01:00
|
|
|
job = Sidekiq::Cron::Job.find name: job_name
|
|
|
|
unless job
|
|
|
|
# schedule a version check, every week at the current day+time
|
|
|
|
# this will prevent that all the instances query the hub simultaneously
|
|
|
|
m = DateTime.current.minute
|
|
|
|
h = DateTime.current.hour
|
|
|
|
d = DateTime.current.cwday
|
|
|
|
job = Sidekiq::Cron::Job.new(name: job_name, cron: "#{m} #{h} * * #{d}", class: 'VersionCheckWorker')
|
|
|
|
job.save
|
|
|
|
end
|
2020-04-07 17:53:19 +02:00
|
|
|
job.enque!
|
2020-01-14 14:33:00 +01:00
|
|
|
end
|
2019-01-31 12:19:50 +01:00
|
|
|
end
|