Skip to content
Permalink
Browse files

PERF: rake posts:rebake_uncooked_posts runs inline

Running this inline makes more sense otherwise there is extreme risk in
saturating sidekiq queue.

This also reworks ordering and selection so we double check if a post needs
rebaking prior to rebaking, this unlocks the ability to run this rake task
from multiple consoles.
  • Loading branch information...
SamSaffron committed Aug 13, 2019
1 parent 213b7d1 commit 7632fe0b58a1e584cd48511b0ac8b8f6c94488ad
Showing with 17 additions and 2 deletions.
  1. +17 −2 lib/tasks/posts.rake
@@ -8,6 +8,11 @@ task 'posts:rebake' => :environment do
end

task 'posts:rebake_uncooked_posts' => :environment do
# rebaking uncooked posts can very quickly saturate sidekiq
# this provides an insurance policy so you can safely run and stop
# this rake task without worrying about your sidekiq imploding
Jobs.run_immediately!

ENV['RAILS_DB'] ? rebake_uncooked_posts : rebake_uncooked_posts_all_sites
end

@@ -24,8 +29,18 @@ def rebake_uncooked_posts
rebaked = 0
total = uncooked.count

uncooked.find_each do |post|
rebake_post(post)
ids = uncooked.pluck(:id)
# work randomly so you can run this job from lots of consoles if needed
ids.shuffle!

ids.each do |id|
# may have been cooked in interim
post = uncooked.where(id: id).first

if post
rebake_post(post)
end

print_status(rebaked += 1, total)
end

0 comments on commit 7632fe0

Please sign in to comment.
You can’t perform that action at this time.