diff --git a/Gemfile b/Gemfile index 1a0cc9c1f9..40069d9263 100644 --- a/Gemfile +++ b/Gemfile @@ -98,8 +98,6 @@ gem 'icalendar', require: false gem "jwt" # Use Newrelic for logs and APM gem "newrelic_rpm" -# Scheduling -gem 'rufus-scheduler' # Used to manage periodic cron-like jobs gem "clockwork" diff --git a/Gemfile.lock b/Gemfile.lock index 8cf94f8a48..bd4fbb8bb5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -184,8 +184,6 @@ GEM dry-logic (~> 1.4) zeitwerk (~> 2.6) erubi (1.12.0) - et-orbi (1.2.7) - tzinfo execjs (2.9.1) factory_bot (6.4.5) activesupport (>= 5.0.0) @@ -239,9 +237,6 @@ GEM sanitize (< 7) foreman (0.87.2) formatador (1.1.0) - fugit (1.8.1) - et-orbi (~> 1, >= 1.2.7) - raabro (~> 1.4) geocoder (1.8.2) globalid (1.2.1) activesupport (>= 6.1) @@ -437,7 +432,6 @@ GEM public_suffix (5.0.4) puma (6.4.2) nio4r (~> 2.0) - raabro (1.4.0) racc (1.7.3) rack (2.2.8) rack-protection (3.1.0) @@ -548,8 +542,6 @@ GEM ruby-vips (2.1.4) ffi (~> 1.12) ruby2_keywords (0.0.5) - rufus-scheduler (3.9.1) - fugit (~> 1.1, >= 1.1.6) sanitize (6.1.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -725,7 +717,6 @@ DEPENDENCIES rubocop rubocop-performance rubocop-rails (~> 2.23.1) - rufus-scheduler sass-rails shoulda-matchers (~> 6.1) simple_form diff --git a/clock.rb b/clock.rb index 19297cfe78..9c5fb0d81d 100644 --- a/clock.rb +++ b/clock.rb @@ -9,6 +9,18 @@ module Clockwork puts "Running #{job}" end + DATA_TYPES = %w[Distribution Purchase Donation] + every(1.day, "Cache historical data", at: "03:00") do + Organization.is_active.each do |org| + DATA_TYPES.each do |type| + Rails.logger.info("Queuing up #{type} cache data for #{org.name}") + HistoricalDataCacheJob.perform_later(org_id: org.id, type: type) + end + end + + Rails.logger.info("Done!") + end + every(1.day, "Periodically reset seed data in staging", at: "00:00") do if ENV["RAILS_ENV"] == "staging" rake = Rake.application diff --git a/config/initializers/task_scheduler.rb b/config/initializers/task_scheduler.rb deleted file mode 100644 index 67642ba5a2..0000000000 --- a/config/initializers/task_scheduler.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'rufus-scheduler' - -scheduler = Rufus::Scheduler.singleton - -scheduler.cron '0 3 * * *' do - system('bundle exec rake cache_historical_data') -end diff --git a/db/migrate/20240202201155_cleanup_delayed_jobs.rb b/db/migrate/20240202201155_cleanup_delayed_jobs.rb new file mode 100644 index 0000000000..c4125dd18e --- /dev/null +++ b/db/migrate/20240202201155_cleanup_delayed_jobs.rb @@ -0,0 +1,7 @@ +class CleanupDelayedJobs < ActiveRecord::Migration[7.0] + def change + Delayed::Job. + where(locked_at: nil, failed_at: nil). + where("handler LIKE '%HistoricalDataCacheJob%'").delete_all + end +end diff --git a/lib/tasks/cache_historical_data.rake b/lib/tasks/cache_historical_data.rake deleted file mode 100644 index 88431f4856..0000000000 --- a/lib/tasks/cache_historical_data.rake +++ /dev/null @@ -1,16 +0,0 @@ -desc "This task is run by a scheduling tool nightly to cache the processor intensive queries" -task :cache_historical_data => :environment do - Rails.logger.info("Caching historical data") - DATA_TYPES = ['Distribution', 'Purchase', 'Donation'] - - orgs = Organization.is_active - - orgs.each do |org| - DATA_TYPES.each do |type| - puts "Queuing up #{type} cache data for #{org.name}" - HistoricalDataCacheJob.perform_later(org_id: org.id, type: type) - end - end - - Rails.logger.info("Done!") -end