inkbunny missing posts task fixes

This commit is contained in:
Dylan Knutson
2025-08-18 23:58:06 +00:00
parent a68e5b0112
commit 7f521b30e9
4 changed files with 20 additions and 13 deletions

View File

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

View File

@@ -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
if always_recheck
@inferred_queue_size = queue_size
else
@inferred_queue_size += 1
end
@total_performed += 1
end

View File

@@ -60,13 +60,11 @@ 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
enqueue(always_recheck: true) do
Domain::Inkbunny::Job::UpdatePostsJob.perform_now(
ib_post_ids: missing_ib_post_ids,
)
end
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

View File

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