From 934c8e3b87ec5cf926b60bc33bb21f8d5efd13fc Mon Sep 17 00:00:00 2001 From: Earlopain Date: Fri, 9 Dec 2022 18:16:53 +0100 Subject: [PATCH] [Docker] Run daily maintenance Remove whenever, it's not used in prod. Prod uses systemd timers. This executes the daily task on container startup. My PC isn't going to run when this would execute 99% of the time. --- Gemfile | 1 - Gemfile.lock | 4 --- Procfile | 3 +- app/logical/maintenance.rb | 4 --- bin/whenever | 29 -------------------- bin/wheneverize | 29 -------------------- config/schedule.rb | 18 ------------ docker-compose.yml | 1 + docker/cron_tasks/daily/daily_maintenance.sh | 4 +++ lib/tasks/maintenance.rake | 10 ------- 10 files changed, 7 insertions(+), 96 deletions(-) delete mode 100755 bin/whenever delete mode 100755 bin/wheneverize delete mode 100644 config/schedule.rb create mode 100755 docker/cron_tasks/daily/daily_maintenance.sh diff --git a/Gemfile b/Gemfile index c31bc4726..e4b00f1e8 100644 --- a/Gemfile +++ b/Gemfile @@ -7,7 +7,6 @@ gem "pg" gem "dalli", :platforms => :ruby gem "simple_form" gem 'active_model_serializers', '~> 0.10.0' -gem "whenever", :require => false gem "sanitize" gem 'ruby-vips' gem 'diff-lcs', :require => "diff/lcs/array" diff --git a/Gemfile.lock b/Gemfile.lock index b5c5bdba7..4137ade32 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -98,7 +98,6 @@ GEM byebug (11.1.3) case_transform (0.2) activesupport - chronic (0.10.2) cityhash (0.9.0) coderay (1.1.3) concurrent-ruby (1.1.10) @@ -386,8 +385,6 @@ GEM websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - whenever (1.0.0) - chronic (>= 0.6.3) yard (0.9.28) webrick (~> 1.7.0) zeitwerk (2.6.1) @@ -442,7 +439,6 @@ DEPENDENCIES unicorn-worker-killer webmock webpacker (>= 4.0.x) - whenever BUNDLED WITH 2.3.12 diff --git a/Procfile b/Procfile index 24e845160..441f02216 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,3 @@ -unicorn: bin/rails server -p 9000 -b 0.0.0.0 +server: bin/rails server -p 9000 -b 0.0.0.0 jobs: bundle exec sidekiq -c 1 -q low_prio -q tags -q default -q high_prio -q video +cron: run-parts /etc/periodic/daily && crond -f diff --git a/app/logical/maintenance.rb b/app/logical/maintenance.rb index 96c835bfa..78c37ce1b 100644 --- a/app/logical/maintenance.rb +++ b/app/logical/maintenance.rb @@ -14,10 +14,6 @@ module Maintenance ignoring_exceptions { StatsUpdater.run! } end - def weekly - return if Danbooru.config.readonly_mode? - end - def ignoring_exceptions(&block) ActiveRecord::Base.connection.execute("set statement_timeout = 0") yield diff --git a/bin/whenever b/bin/whenever deleted file mode 100755 index e5d6eb666..000000000 --- a/bin/whenever +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'whenever' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -bundle_binstub = File.expand_path("../bundle", __FILE__) - -if File.file?(bundle_binstub) - if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/ - load(bundle_binstub) - else - abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. -Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") - end -end - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("whenever", "whenever") diff --git a/bin/wheneverize b/bin/wheneverize deleted file mode 100755 index 8776f5bd7..000000000 --- a/bin/wheneverize +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'wheneverize' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -bundle_binstub = File.expand_path("../bundle", __FILE__) - -if File.file?(bundle_binstub) - if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/ - load(bundle_binstub) - else - abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. -Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") - end -end - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("whenever", "wheneverize") diff --git a/config/schedule.rb b/config/schedule.rb deleted file mode 100644 index 23660acb9..000000000 --- a/config/schedule.rb +++ /dev/null @@ -1,18 +0,0 @@ -set :output, "/var/log/whenever.log" -#env "MAILTO", "webmaster@danbooru.donmai.us" - -every 1.hour do - rake "maintenance:hourly" -end - -every 1.day do - rake "maintenance:daily" -end - -every 1.day, :at => "1:00 am" do - command "psql --set statement_timeout=0 -h inuyama -c \"vacuum analyze;\" danbooru2" -end - -every 1.week, :at => "1:30 am" do - rake "maintenance:weekly" -end diff --git a/docker-compose.yml b/docker-compose.yml index 382c416ec..8ec95583b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -33,6 +33,7 @@ services: - node_modules:/app/node_modules - public_packs:/app/public/packs - post_data:/app/public/data + - ./docker/cron_tasks/daily:/etc/periodic/daily environment: <<: *common-env RAILS_ENV: development diff --git a/docker/cron_tasks/daily/daily_maintenance.sh b/docker/cron_tasks/daily/daily_maintenance.sh new file mode 100755 index 000000000..5e2185be2 --- /dev/null +++ b/docker/cron_tasks/daily/daily_maintenance.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +echo "Running daily maintenance" +cd /app && bundle exec rake maintenance:daily +echo "Finished daily maintenance" diff --git a/lib/tasks/maintenance.rake b/lib/tasks/maintenance.rake index 812103d4e..668759007 100644 --- a/lib/tasks/maintenance.rake +++ b/lib/tasks/maintenance.rake @@ -1,18 +1,8 @@ require "tasks/newrelic" if defined?(NewRelic) namespace :maintenance do - desc "Run hourly maintenance jobs" - task hourly: :environment do - Maintenance.hourly - end - desc "Run daily maintenance jobs" task daily: :environment do Maintenance.daily end - - desc "Run weekly maintenance jobs" - task weekly: :environment do - Maintenance.weekly - end end