1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

prevent version check from running multiple times + updated sidekiq

This commit is contained in:
Sylvain 2020-03-04 10:35:00 +01:00
parent 9e618274fc
commit 8fca92b8ae
3 changed files with 21 additions and 14 deletions

View File

@ -34,6 +34,7 @@
- Updated moment-timezone
- Updated angular-ui-bootstrap from v0.14 to v1.2
- Updated caxlsx to 3.0.1 and rails_axlsx to rails_caxlsx
- Updated sidekiq to 5.2.8
- Option to disable developers analytics
- Added the a "cron" tab in Sidekiq web-ui to watch scheduled tasks
- Integration of Crowdin "in-context" translation management system

View File

@ -276,7 +276,7 @@ GEM
pundit (1.0.0)
activesupport (>= 3.0.0)
raabro (1.1.6)
rack (1.6.12)
rack (1.6.13)
rack-protection (1.5.5)
rack
rack-test (0.6.3)
@ -323,7 +323,7 @@ GEM
recurrence (1.3.0)
activesupport
i18n
redis (4.1.2)
redis (4.1.3)
redis-namespace (1.6.0)
redis (>= 3.0.4)
ref (2.0.0)
@ -360,9 +360,9 @@ GEM
activerecord (~> 4)
activesupport (~> 4)
sha3 (1.0.1)
sidekiq (5.2.7)
sidekiq (5.2.8)
connection_pool (~> 2.2, >= 2.2.2)
rack (>= 1.5.0)
rack (< 2.1.0)
rack-protection (>= 1.5.0)
redis (>= 3.3.5, < 5)
sidekiq-cron (1.1.0)

View File

@ -1,12 +1,14 @@
# frozen_string_literal: true
# retrieve the current Fab-manager version
# retrieve the Fab-manager's versions
class Version
# currently installed
def self.current
package = File.read('package.json')
JSON.parse(package)['version']
end
# currently published
def self.up_to_date?
hub_version = Setting.find_by(name: 'hub_last_version')&.value
return unless hub_version
@ -15,17 +17,21 @@ class Version
json['up_to_date']
end
# periodically retrieve the last published version from the hub and save it into the database
def self.check_and_schedule
job_name = 'Automatic version check'
return if (Rails.env.development? || Rails.env.test?) && ENV['FORCE_VERSION_CHECK'] != 'true'
VersionCheckWorker.perform_async
return if Sidekiq::Cron::Job.find name: 'Automatic version check'
# schedule version check every day at the current time
# this will prevent that all the instances to query the hub simultaneously
m = DateTime.current.minute
h = DateTime.current.hour
d = DateTime.current.cwday
Sidekiq::Cron::Job.create(name: 'Automatic version check', cron: "#{m} #{h} * * #{d}", class: 'VersionCheckWorker')
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
job.enque! if !job.last_enqueue_time || job.last_enqueue_time < DateTime.current - 24.hours
end
end