Skip to content
Iterate over Enumerables with progress reporting.
Branch: master
Clone or download
Latest commit b2d75f3 Jun 19, 2013
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Add examples. Jun 5, 2013
lib Version bump. Jun 19, 2013
test Prefer BATCH_DEBUG for halting since $DEBUG is way too verbose. Jun 19, 2013
.gems
.gitignore Release. Dec 7, 2012
README.markdown
Rakefile
UNLICENSE Release. Dec 7, 2012
batch.gemspec Release. Jan 21, 2013
batch.gemspec.erb Version bump. Jul 18, 2010

README.markdown

Batch

Keep your batch jobs under control.

Description

Say you have a thousand images to process. You write a script, fire it and go to bed, only to realize the morning after that an exception was raised and the script was aborted. Well, no more frustration: now you can use Batch to make sure your script continues working despite those exceptions, and you can now get a nice report to read while you drink your morning coffee.

Usage

require "batch"

Batch.each(Model.all) do |model|
  # do something with model
  # and see the overall progress
end

Given that Model.all responds to each and size, you'll get a nice progress report:

  0% ...........................................................................
 25% ...........................................................................
 50% ...........................................................................
 75% ...........................................................................
100%

If errors occur, they are handled so that your long-running scripts don't get interrupted right after you go to bed:

  0% .......E...................................................................
 25% ..........................................E................................
 50% ....................E......................................................
 75% ...........................................................................
100%

Some errors occured:

# ... detailed exceptions here

You can determine the line width by setting the environment variable BATCH_WIDTH, which defaults to 75.

Disabling output

On some environments, like a non-interactive shell, you probably want Batch to still run your stuff and skip errors, but you don't want all the progress output. For this purpose you can tweak BATCH_INTERACTIVE:

$ BATCH_INTERACTIVE=0 rake foo

It's probably useful to have BATCH_INTERACTIVE set to 0 on your crontabs.

Debugging

If you want Batch to halt as soon as there's an exception (just like a regular each loop would do), set BATCH_DEBUG:

$ BATCH_DEBUG=1 ruby <your-batch-script>

Batch will also honor the $DEBUG flag and halt if an exception is caught.

Installation

$ gem install batch
You can’t perform that action at this time.