From 7f521b30e930df04cef6e44f09f415d1fdd72e82 Mon Sep 17 00:00:00 2001 From: Dylan Knutson Date: Mon, 18 Aug 2025 23:58:06 +0000 Subject: [PATCH] inkbunny missing posts task fixes --- app/jobs/domain/static_file_job_helper.rb | 4 +++- app/lib/enqueue_job_base.rb | 10 +++++++--- .../inkbunny/enqueue_missing_posts_task.rb | 17 +++++++++-------- rake/ib.rake | 2 +- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/app/jobs/domain/static_file_job_helper.rb b/app/jobs/domain/static_file_job_helper.rb index e4e567cf..a414edf1 100644 --- a/app/jobs/domain/static_file_job_helper.rb +++ b/app/jobs/domain/static_file_job_helper.rb @@ -105,7 +105,9 @@ module Domain::StaticFileJobHelper end end ensure - post_file.save! if post_file + post_file.save! + post = post_file.post + post.touch if post if should_enqueue_thumbnail_job defer_job(Domain::PostFileThumbnailJob, { post_file: }) end diff --git a/app/lib/enqueue_job_base.rb b/app/lib/enqueue_job_base.rb index 42a96d8a..f3a95ce2 100644 --- a/app/lib/enqueue_job_base.rb +++ b/app/lib/enqueue_job_base.rb @@ -45,8 +45,8 @@ class EnqueueJobBase < Tasks::InterruptableTask def start_enqueuing end - sig { params(block: T.proc.void).void } - def enqueue(&block) + sig { params(always_recheck: T::Boolean, block: T.proc.void).void } + def enqueue(always_recheck: false, &block) # if we're under the high water mark, we can just enqueue and return # so we get called again as soon as possible if @inferred_queue_size < high_water_mark @@ -64,7 +64,11 @@ class EnqueueJobBase < Tasks::InterruptableTask end block.call - @inferred_queue_size += 1 + if always_recheck + @inferred_queue_size = queue_size + else + @inferred_queue_size += 1 + end @total_performed += 1 end diff --git a/app/lib/tasks/inkbunny/enqueue_missing_posts_task.rb b/app/lib/tasks/inkbunny/enqueue_missing_posts_task.rb index 0f83eef9..351bc661 100644 --- a/app/lib/tasks/inkbunny/enqueue_missing_posts_task.rb +++ b/app/lib/tasks/inkbunny/enqueue_missing_posts_task.rb @@ -60,12 +60,10 @@ class Tasks::Inkbunny::EnqueueMissingPostsTask < EnqueueJobBase missing_ib_post_ids = T.cast(missing_ib_post_ids, T::Array[Integer]) if found_min_id = missing_ib_post_ids.min - enqueue do - ColorLogger.quiet do - Domain::Inkbunny::Job::UpdatePostsJob.perform_now( - ib_post_ids: missing_ib_post_ids, - ) - end + enqueue(always_recheck: true) do + Domain::Inkbunny::Job::UpdatePostsJob.perform_now( + ib_post_ids: missing_ib_post_ids, + ) end # Move to continue from the lowest ID we just processed max_ib_post_id = found_min_id @@ -82,13 +80,16 @@ class Tasks::Inkbunny::EnqueueMissingPostsTask < EnqueueJobBase end # Stop if we've reached the beginning - save_progress([max_ib_post_id, 0].max.to_s) + max_ib_post_id = [max_ib_post_id, 0].max + save_progress(max_ib_post_id.to_s) + logger.info("saved progress: #{max_ib_post_id}") break if max_ib_post_id <= 0 + break if interrupted? end end sig { override.returns(Integer) } def queue_size - count_failed_in_queue("inkbunny") + count_failed_in_queue(%w[inkbunny static_file]) end end diff --git a/rake/ib.rake b/rake/ib.rake index 2f8f02ec..41ab53c8 100644 --- a/rake/ib.rake +++ b/rake/ib.rake @@ -10,7 +10,7 @@ namespace :ib do desc "Enqueue missing posts" task enqueue_missing_posts: :environment do - Tasks::Inkbunny::EnqueueMissingPostsTask.new.run + Tasks::Inkbunny::EnqueueMissingPostsTask.new(start_at: ENV["start_at"]).run end desc "set auth credentials"