LoginSignup
4
4

More than 5 years have passed since last update.

railsでバッチ処理する問に、小分けにして進捗も出す

Posted at
sample.rb
articles = Article
total_count = articles.count
per_batch = 2000
0.step(total_count, per_batch) do |offset|
  articles.limit(per_batch).skip(offset).each.with_index(offset) do |article, i|
    puts "#{i}/#{total_count}"
    STDOUT.flush #nohup時に逐次表示させる
  end
end
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4