good_job cron for periodic tasks

This commit is contained in:
Dylan Knutson
2025-01-27 18:41:05 +00:00
parent 49fd8ccd48
commit dc6965ab7b
3 changed files with 50 additions and 22 deletions

View File

@@ -37,27 +37,6 @@ task periodic_tasks: %i[environment set_logger_stdout] do
end
end
Thread.new do
loop do
Rake::Task["fa:browse_page_job"].execute
Rake::Task["fa:home_page_job"].execute
Rake::Task["e621:posts_index_job"].execute
puts "enqueue periodic jobs"
sleep 1.minute
end
end
Thread.new do
loop do
puts "enqueue inkbunny latest posts"
Domain::Inkbunny::Job::LatestPostsJob.set(
queue: "inkbunny",
priority: -20,
).perform_later({})
sleep 2.minutes
end
end
loop { sleep 10 }
end
@@ -85,6 +64,7 @@ task good_job: %i[environment set_ar_stdout set_logger_stdout] do
"GOOD_JOB_MAX_CACHE" => "10000",
"GOOD_JOB_QUEUE_SELECT_LIMIT" => "4096",
"GOOD_JOB_MAX_THREADS" => "4",
"GOOD_JOB_ENABLE_CRON" => "1",
"GOOD_JOB_QUEUES" =>
ENV["GOOD_JOB_QUEUES"] ||
%w[manual:4 fa_post,e621:2 *:6].reject(&:nil?).join(";"),

View File

@@ -27,7 +27,7 @@ Rails.application.configure do
config.cache_store = :memory_store
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=#{2.days.to_i}"
"Cache-Control" => "public, max-age=#{2.days.to_i}",
}
else
config.action_controller.perform_caching = false
@@ -69,4 +69,7 @@ Rails.application.configure do
# Uncomment if you wish to allow Action Cable access from any origin.
config.action_cable.disable_request_forgery_protection = true
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
end

View File

@@ -23,6 +23,51 @@ Rails.application.configure do
else
config.good_job.execution_mode = :external
end
config.good_job.enable_cron = true
config.good_job.cron_graceful_restart_period = 2.minutes
config.good_job.cron = {
inkbunny_latest_posts: { # each recurring job must have a unique key
cron: "*/2 * * * *",
class: "Domain::Inkbunny::Job::LatestPostsJob",
args: [{}],
set: {
queue: "manual",
priority: -20,
},
description: "Inkbunny, enqueue latest posts",
},
fa_browse_page_job: {
cron: "*/1 * * * *",
class: "Domain::Fa::Job::BrowsePageJob",
args: [{}],
set: {
queue: "manual",
priority: -20,
},
description: "FurAffinity, scan browse page",
},
fa_home_page_job: {
cron: "*/1 * * * *",
class: "Domain::Fa::Job::HomePageJob",
args: [{}],
set: {
queue: "manual",
priority: -20,
},
description: "FurAffinity, scan home page",
},
e621_posts_index_job: {
cron: "*/1 * * * *",
class: "Domain::E621::Job::PostsIndexJob",
args: [{}],
set: {
queue: "manual",
priority: -20,
},
description: "e621, index posts",
},
}
end
ActiveSupport.on_load(:good_job_application_controller) do