diff --git a/Gemfile.lock b/Gemfile.lock index 517e2e7..9df4a32 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,29 +1,29 @@ GEM remote: https://rubygems.org/ specs: - actioncable (7.2.1.1) - actionpack (= 7.2.1.1) - activesupport (= 7.2.1.1) + actioncable (7.2.1.2) + actionpack (= 7.2.1.2) + activesupport (= 7.2.1.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.2.1.1) - actionpack (= 7.2.1.1) - activejob (= 7.2.1.1) - activerecord (= 7.2.1.1) - activestorage (= 7.2.1.1) - activesupport (= 7.2.1.1) + actionmailbox (7.2.1.2) + actionpack (= 7.2.1.2) + activejob (= 7.2.1.2) + activerecord (= 7.2.1.2) + activestorage (= 7.2.1.2) + activesupport (= 7.2.1.2) mail (>= 2.8.0) - actionmailer (7.2.1.1) - actionpack (= 7.2.1.1) - actionview (= 7.2.1.1) - activejob (= 7.2.1.1) - activesupport (= 7.2.1.1) + actionmailer (7.2.1.2) + actionpack (= 7.2.1.2) + actionview (= 7.2.1.2) + activejob (= 7.2.1.2) + activesupport (= 7.2.1.2) mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (7.2.1.1) - actionview (= 7.2.1.1) - activesupport (= 7.2.1.1) + actionpack (7.2.1.2) + actionview (= 7.2.1.2) + activesupport (= 7.2.1.2) nokogiri (>= 1.8.5) racc rack (>= 2.2.4, < 3.2) @@ -32,15 +32,15 @@ GEM rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) useragent (~> 0.16) - actiontext (7.2.1.1) - actionpack (= 7.2.1.1) - activerecord (= 7.2.1.1) - activestorage (= 7.2.1.1) - activesupport (= 7.2.1.1) + actiontext (7.2.1.2) + actionpack (= 7.2.1.2) + activerecord (= 7.2.1.2) + activestorage (= 7.2.1.2) + activesupport (= 7.2.1.2) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.2.1.1) - activesupport (= 7.2.1.1) + actionview (7.2.1.2) + activesupport (= 7.2.1.2) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) @@ -64,26 +64,26 @@ GEM sassc sassc-rails xdan-datetimepicker-rails (~> 2.5.1) - activejob (7.2.1.1) - activesupport (= 7.2.1.1) + activejob (7.2.1.2) + activesupport (= 7.2.1.2) globalid (>= 0.3.6) - activemodel (7.2.1.1) - activesupport (= 7.2.1.1) + activemodel (7.2.1.2) + activesupport (= 7.2.1.2) activemodel-serializers-xml (1.0.3) activemodel (>= 5.0.0.a) activesupport (>= 5.0.0.a) builder (~> 3.1) - activerecord (7.2.1.1) - activemodel (= 7.2.1.1) - activesupport (= 7.2.1.1) + activerecord (7.2.1.2) + activemodel (= 7.2.1.2) + activesupport (= 7.2.1.2) timeout (>= 0.4.0) - activestorage (7.2.1.1) - actionpack (= 7.2.1.1) - activejob (= 7.2.1.1) - activerecord (= 7.2.1.1) - activesupport (= 7.2.1.1) + activestorage (7.2.1.2) + actionpack (= 7.2.1.2) + activejob (= 7.2.1.2) + activerecord (= 7.2.1.2) + activesupport (= 7.2.1.2) marcel (~> 1.0) - activesupport (7.2.1.1) + activesupport (7.2.1.2) base64 bigdecimal concurrent-ruby (~> 1.0, >= 1.3.1) @@ -210,7 +210,7 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (2.7.2) + json (2.7.3) kaminari (1.2.2) activesupport (>= 4.1.0) kaminari-actionview (= 1.2.2) @@ -286,20 +286,20 @@ GEM rackup (2.1.0) rack (>= 3) webrick (~> 1.8) - rails (7.2.1.1) - actioncable (= 7.2.1.1) - actionmailbox (= 7.2.1.1) - actionmailer (= 7.2.1.1) - actionpack (= 7.2.1.1) - actiontext (= 7.2.1.1) - actionview (= 7.2.1.1) - activejob (= 7.2.1.1) - activemodel (= 7.2.1.1) - activerecord (= 7.2.1.1) - activestorage (= 7.2.1.1) - activesupport (= 7.2.1.1) + rails (7.2.1.2) + actioncable (= 7.2.1.2) + actionmailbox (= 7.2.1.2) + actionmailer (= 7.2.1.2) + actionpack (= 7.2.1.2) + actiontext (= 7.2.1.2) + actionview (= 7.2.1.2) + activejob (= 7.2.1.2) + activemodel (= 7.2.1.2) + activerecord (= 7.2.1.2) + activestorage (= 7.2.1.2) + activesupport (= 7.2.1.2) bundler (>= 1.15.0) - railties (= 7.2.1.1) + railties (= 7.2.1.2) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -307,9 +307,9 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.2.1.1) - actionpack (= 7.2.1.1) - activesupport (= 7.2.1.1) + railties (7.2.1.2) + actionpack (= 7.2.1.2) + activesupport (= 7.2.1.2) irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) @@ -337,7 +337,7 @@ GEM responders (3.1.1) actionpack (>= 5.2) railties (>= 5.2) - rexml (3.3.8) + rexml (3.3.9) rollbar (3.6.0) rspec-core (3.13.2) rspec-support (~> 3.13.0) @@ -419,8 +419,7 @@ GEM websocket (~> 1.0) shoulda-matchers (6.4.0) activesupport (>= 5.2.0) - sidekiq (7.3.2) - concurrent-ruby (< 2) + sidekiq (7.3.4) connection_pool (>= 2.3.0) logger rack (>= 2.2.4) diff --git a/app/sidekiq/pg/capture_query_stats_job.rb b/app/sidekiq/pg/capture_query_stats_job.rb index c308db4..5f54083 100644 --- a/app/sidekiq/pg/capture_query_stats_job.rb +++ b/app/sidekiq/pg/capture_query_stats_job.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "sidekiq-scheduler" - module Pg class CaptureQueryStatsJob include Sidekiq::Job diff --git a/app/sidekiq/pg/clear_query_stats_job.rb b/app/sidekiq/pg/clear_query_stats_job.rb index e5e9f72..d13dc8a 100644 --- a/app/sidekiq/pg/clear_query_stats_job.rb +++ b/app/sidekiq/pg/clear_query_stats_job.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "sidekiq-scheduler" - module Pg class ClearQueryStatsJob include Sidekiq::Job diff --git a/config.ru b/config.ru index 2e03084..f45062b 100644 --- a/config.ru +++ b/config.ru @@ -4,5 +4,8 @@ require_relative "config/environment" +require 'sidekiq/web' +require 'sidekiq-scheduler/web' + run Rails.application Rails.application.load_server diff --git a/config/initializers/sidekiq_scheduler.rb b/config/initializers/sidekiq_scheduler.rb new file mode 100644 index 0000000..78430e4 --- /dev/null +++ b/config/initializers/sidekiq_scheduler.rb @@ -0,0 +1,12 @@ +Sidekiq.configure_server do |config| + config.on(:startup) do + schedule_file = Rails.root.join("config/scheduler/#{Rails.env}.yml") + + if File.exist?(schedule_file) + Sidekiq.schedule = YAML.load_file(schedule_file) + SidekiqScheduler::Scheduler.instance.reload_schedule! + else + Rails.logger.info "No schedule file found for #{Rails.env}. Skipping job scheduling." + end + end +end diff --git a/config/sidekiq.yml b/config/scheduler/production.yml similarity index 80% rename from config/sidekiq.yml rename to config/scheduler/production.yml index c50951c..ff7123f 100644 --- a/config/sidekiq.yml +++ b/config/scheduler/production.yml @@ -1,11 +1,9 @@ :scheduler: :schedule: capture_query_stats_job: - :environment: production cron: "0 * * * *" # Runs every hour class: "Pg::CaptureQueryStatsJob" clear_query_stats_job: - :environment: production cron: "0 0 * * 0" # Runs weekly on Sundays at midnight class: "Pg::ClearQueryStatsJob"