diff --git a/Gemfile b/Gemfile index e7e5de3..2e119d2 100644 --- a/Gemfile +++ b/Gemfile @@ -73,7 +73,6 @@ gem "redis", "~> 5.0" gem "rubocop", "~> 1.57" gem "rubocop-erb", "~> 0.3.0" gem "rubocop-rails", "~> 2.22" -gem "whenever", "~> 1.0" gem "filesize", "~> 0.2.0" diff --git a/Gemfile.lock b/Gemfile.lock index b5c0cb6..1c364a2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -115,7 +115,6 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - chronic (0.10.2) concurrent-ruby (1.2.2) connection_pool (2.4.1) crass (1.0.6) @@ -343,8 +342,6 @@ GEM websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - whenever (1.0.0) - chronic (>= 0.6.3) xpath (3.2.0) nokogiri (~> 1.8) zeitwerk (2.6.12) @@ -387,7 +384,6 @@ DEPENDENCIES timeout (~> 0.4.1) tzinfo-data web-console - whenever (~> 1.0) RUBY VERSION ruby 3.2.2p53 diff --git a/Procfile b/Procfile index 39a81b5..85b7507 100644 --- a/Procfile +++ b/Procfile @@ -1,3 +1,2 @@ server: bin/rails server -p 3000 -b 0.0.0.0 -cron: bundler exec whenever --set environment="$RAILS_ENV" --update-crontab && crond -f jobs: bundle exec good_job start diff --git a/Procfile.dev b/Procfile.dev index 0f37947..ab90747 100644 --- a/Procfile.dev +++ b/Procfile.dev @@ -1,4 +1,3 @@ server: bin/rails server -p 3000 -b 0.0.0.0 assets: yarn build --watch -cron: bundler exec whenever --set environment="$RAILS_ENV" --update-crontab && crond -f jobs: bundle exec good_job start diff --git a/app/jobs/e621_exports_job.rb b/app/jobs/e621_exports_job.rb new file mode 100644 index 0000000..dede0c5 --- /dev/null +++ b/app/jobs/e621_exports_job.rb @@ -0,0 +1,12 @@ +class E621ExportsJob < ApplicationJob + queue_as :low_priority + + def perform + E621.constants.map { |c| E621.const_get(c) }.filter { |c| c < ApplicationRecord }.each do |type| + Rails.logger.debug { "Updating #{type}" } + type.sync! + end + E621::Pool.sync_tags! + E621PoolImportJob.perform_now + end +end diff --git a/app/jobs/e621_status_update_job.rb b/app/jobs/e621_status_update_job.rb new file mode 100644 index 0000000..ead9930 --- /dev/null +++ b/app/jobs/e621_status_update_job.rb @@ -0,0 +1,7 @@ +class E621StatusUpdateJob < ApplicationJob + queue_as :low_priority + + def perform + E621StatusUpdater.run + end +end diff --git a/config/environments/production.rb b/config/environments/production.rb index a04b804..3b4f3a7 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -89,6 +89,17 @@ Rails.application.configure do # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false + config.good_job.cron = { + e621_status_update: { + cron: "* * * * *", + class: "E621StatusUpdateJob", + }, + e621_exports: { + cron: "50 10 * * *", + class: "E621ExportsJob", + }, + } + # Enable DNS rebinding protection and other `Host` header attacks. # config.hosts = [ # "example.com", # Allow requests from example.com diff --git a/config/schedule.rb b/config/schedule.rb deleted file mode 100644 index 87a8fac..0000000 --- a/config/schedule.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true - -# Use this file to easily define all of your cron jobs. -# -# It's helpful, but not entirely necessary to understand cron before proceeding. -# http://en.wikipedia.org/wiki/Cron - -# Example: -# -# set :output, "/path/to/my/cron_log.log" -# -# every 2.hours do -# command "/usr/bin/some_great_command" -# runner "MyModel.some_method" -# rake "some:great:rake:task" -# end -# -# every 4.days do -# runner "AnotherModel.prune_old_records" -# end - -# Learn more: http://github.com/javan/whenever - -set :job_template, "/bin/sh -c ':job'" -set :output, "log/cron.log" - -# Perform an e621 status update every minute -every 1.minute do - rake "e621:status_update" -end - -# Update e621 exports at 12AM UTC -# E621 generates them somewhere around 7AM UTC (usually finishing around 7:45AM), but we're being safe -every :day, at: "10:50am" do - rake "e621:exports" -end diff --git a/lib/tasks/e621.rake b/lib/tasks/e621.rake index 7c9b92e..e45d283 100644 --- a/lib/tasks/e621.rake +++ b/lib/tasks/e621.rake @@ -3,7 +3,7 @@ namespace :e621 do desc "Tasks related to e621" task status_update: :environment do - E621StatusUpdater.run + E621StatusUpdateJob.perform_now end task remove_timeouts: :environment do