0.0
No commit activity in last 3 years
No release in over 3 years
Simple gem for regular progress logging in a long-running loop, log every N actions, or based on a time interval
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0.2.0
>= 1.2.9
 Project Readme

(Full rdocs are hosted on github at kornysietsma.github.com/progress-logger/rdoc/index.html )


ProgressLogger¶ ↑

This is a very simple gem to make it easier to log the state of long slow processing jobs. I tend to do this sort of thing over and over and over:

count = 0
@collection.each do |record|
  count += 1
  if count % 1000000 == 0
    puts "Processed #{count} rows"
  end
  # do stuff
end

with variations for timed reporting, calculating processing rate, and so on. ProgressLogger really doesn’t do much - it just tries to handle the interval checking, leaving what you do every million records (or whatever) entirely up to you. The example above can be run as:

require 'progress-logger'

p = ProgressLogger.new(:count => 1000000) do |state|
  puts "Processed #{state.count} rows"
end
@collection.each do |record|
  p.trigger
  # do stuff
end

You can do lots of other stuff too - see the ProgressLogger rdocs for more, but an example to whet your appetite:

p = ProgressLogger.new(:count => 1000000, :minutes => 30, :max => @collection.size) do |state|
  @logger.info("Processed #{state.count} rows - #{state.long_eta/(60*60)} hours to go!")
  @cache.flush()
end

More examples are in the ProgressLogger docs - or take a look at the specs!

Note on Patches/Pull Requests¶ ↑

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 Kornelis Sietsma. See LICENSE for details.