move cron jobs into good job

This commit is contained in:
Donovan Daniels 2024-08-06 06:21:24 -05:00
parent 9a55d1201d
commit 5229867d4d
Signed by: Donovan_DMC
GPG Key ID: 907D29CBFD6157BA
9 changed files with 31 additions and 44 deletions

View File

@ -73,7 +73,6 @@ gem "redis", "~> 5.0"
gem "rubocop", "~> 1.57" gem "rubocop", "~> 1.57"
gem "rubocop-erb", "~> 0.3.0" gem "rubocop-erb", "~> 0.3.0"
gem "rubocop-rails", "~> 2.22" gem "rubocop-rails", "~> 2.22"
gem "whenever", "~> 1.0"
gem "filesize", "~> 0.2.0" gem "filesize", "~> 0.2.0"

View File

@ -115,7 +115,6 @@ GEM
rack-test (>= 0.6.3) rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0) regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2) xpath (~> 3.2)
chronic (0.10.2)
concurrent-ruby (1.2.2) concurrent-ruby (1.2.2)
connection_pool (2.4.1) connection_pool (2.4.1)
crass (1.0.6) crass (1.0.6)
@ -343,8 +342,6 @@ GEM
websocket-driver (0.7.6) websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0) websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5) websocket-extensions (0.1.5)
whenever (1.0.0)
chronic (>= 0.6.3)
xpath (3.2.0) xpath (3.2.0)
nokogiri (~> 1.8) nokogiri (~> 1.8)
zeitwerk (2.6.12) zeitwerk (2.6.12)
@ -387,7 +384,6 @@ DEPENDENCIES
timeout (~> 0.4.1) timeout (~> 0.4.1)
tzinfo-data tzinfo-data
web-console web-console
whenever (~> 1.0)
RUBY VERSION RUBY VERSION
ruby 3.2.2p53 ruby 3.2.2p53

View File

@ -1,3 +1,2 @@
server: bin/rails server -p 3000 -b 0.0.0.0 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 jobs: bundle exec good_job start

View File

@ -1,4 +1,3 @@
server: bin/rails server -p 3000 -b 0.0.0.0 server: bin/rails server -p 3000 -b 0.0.0.0
assets: yarn build --watch assets: yarn build --watch
cron: bundler exec whenever --set environment="$RAILS_ENV" --update-crontab && crond -f
jobs: bundle exec good_job start jobs: bundle exec good_job start

View File

@ -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

View File

@ -0,0 +1,7 @@
class E621StatusUpdateJob < ApplicationJob
queue_as :low_priority
def perform
E621StatusUpdater.run
end
end

View File

@ -89,6 +89,17 @@ Rails.application.configure do
# Do not dump schema after migrations. # Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false 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. # Enable DNS rebinding protection and other `Host` header attacks.
# config.hosts = [ # config.hosts = [
# "example.com", # Allow requests from example.com # "example.com", # Allow requests from example.com

View File

@ -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

View File

@ -3,7 +3,7 @@
namespace :e621 do namespace :e621 do
desc "Tasks related to e621" desc "Tasks related to e621"
task status_update: :environment do task status_update: :environment do
E621StatusUpdater.run E621StatusUpdateJob.perform_now
end end
task remove_timeouts: :environment do task remove_timeouts: :environment do