Progress bar for migration

Snail on wall
Probably it is time to replace my notebook with new one, but before this will happen I need to deal with what I got ;) So problem is with migrations. If they just add/remove database fields it is no problem. But recently I often do a lot computations on my data sets in those. Not that those sets are huge, but staring on console window waiting as those operations end is somewhat frustrating.

Buying new notebook probably would help, but there are some low end solutions. Not for time for those operations, but for lack of feedback.

So welcome to Simple Migration Progress Bar:

#!/usr/bin/env ruby

STDOUT.sync=true
cnt = 0
width = 60
total_cnt=200

while cnt < total_cnt do
  cnt += 1
  prgrs =(cnt.to_f/total_cnt*width).to_i+1
  prgrs = width -1 if prgrs >= width
  str = "|%#{prgrs}s%#{width-prgrs}s\r"
  printf str ,">","|"
  sleep 0.05
end

Ugly code, seems soooo C-ish. Maybe someone will write more Ruby version?

Join the Conversation

5 Comments

  1. @Bragi
    Maybe it is. But IMO progress bar gem should win prize for hardest to find gem ;)

    I mean – googling for progress bar gem does return nothing meaningful…

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.