From 0fe7da6f80a31a069a48492f0a9eb9ebdf82c985 Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 17 May 2024 11:55:04 +0100 Subject: [PATCH] completely disable usage report job if not active --- Gemfile | 2 +- Gemfile.lock | 16 +++++++++++----- app/controllers/settings_controller.rb | 6 +----- app/lib/usage_report.rb | 10 ++++++++++ config/sidekiq.yml | 6 ++---- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/Gemfile b/Gemfile index a01cb0d11..c0bbf9d90 100644 --- a/Gemfile +++ b/Gemfile @@ -135,4 +135,4 @@ gem "logstash-event", "~> 1.2" gem "climate_control", "~> 1.2", group: :test -gem "sidekiq-scheduler", "~> 5.0" +gem "sidekiq-scheduler", github: "manyfold3d/sidekiq-scheduler", branch: "fix-dynamic-schedule-load-on-boot" diff --git a/Gemfile.lock b/Gemfile.lock index 35dd2fbe5..36d86975b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -19,6 +19,16 @@ GIT opengl-bindings rubyzip +GIT + remote: https://github.com/manyfold3d/sidekiq-scheduler.git + revision: 8eb248143c89fae273d66a57b41b474b7006f2bd + branch: fix-dynamic-schedule-load-on-boot + specs: + sidekiq-scheduler (5.0.3) + rufus-scheduler (~> 3.2) + sidekiq (>= 6, < 8) + tilt (>= 1.4.0, < 3) + GEM remote: https://rubygems.org/ specs: @@ -485,10 +495,6 @@ GEM redis-client (>= 0.19.0) sidekiq-failures (1.0.4) sidekiq (>= 4.0.0) - sidekiq-scheduler (5.0.3) - rufus-scheduler (~> 3.2) - sidekiq (>= 6, < 8) - tilt (>= 1.4.0) simple_po_parser (1.1.6) simplecov (0.22.0) docile (~> 1.1) @@ -629,7 +635,7 @@ DEPENDENCIES scout_apm sidekiq (~> 7.2) sidekiq-failures (~> 1.0) - sidekiq-scheduler (~> 5.0) + sidekiq-scheduler! simplecov (~> 0.22.0) spdx (~> 4.1) spring diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index 68246ea43..a981c3cca 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -106,11 +106,7 @@ def update_analysis_settings(settings) def update_usage_settings(settings) return unless settings - if settings[:report] == "1" - SiteSettings.anonymous_usage_id ||= SecureRandom.uuid - else - SiteSettings.anonymous_usage_id = nil - end + (settings[:report] == "1") ? UsageReport.enable! : UsageReport.disable! end def get_user diff --git a/app/lib/usage_report.rb b/app/lib/usage_report.rb index b2d079a9b..e74355f36 100644 --- a/app/lib/usage_report.rb +++ b/app/lib/usage_report.rb @@ -12,4 +12,14 @@ def self.generate end end end + + def self.enable! + SiteSettings.anonymous_usage_id ||= SecureRandom.uuid + Sidekiq.set_schedule("usage", {every: "1d", class: "UsageReportingJob"}) + end + + def self.disable! + SiteSettings.anonymous_usage_id = nil + Sidekiq.remove_schedule("usage") + end end diff --git a/config/sidekiq.yml b/config/sidekiq.yml index b5076d31b..b077c436b 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -4,7 +4,5 @@ - default - analysis :scheduler: - :schedule: - usage: - every: '1d' - class: UsageReportingJob + :dynamic: true + :dynamic_every: 15s