NetManiac

Witold Rugowski on web20 wave with Ruby on Rails

Progress bar for migration

Posted on April 22, 2008 - Filed Under Ruby

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?

Popularity: 14% [?]

Hits for this post: 2854

Similar Posts

Comments

5 Responses to “Progress bar for migration”

  1. Tomek on April 23rd, 2008 8:38

    (…)But before this will happen I need to deal with what I got ;) (…)

    Deal You are saying. Bad expirience from the past You have?

  2. Bragi on April 23rd, 2008 12:02

    Not ugly but fugly :)

    Check the progressbar gem.

  3. NetManiac on April 23rd, 2008 12:54

    @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…

  4. Tomek on April 23rd, 2008 21:42

    @NetManiac
    Skills in googling improve You must:
    http://rubygems.org/read/chapter/4

  5. NetManiac on April 23rd, 2008 21:45

    To improve truly I need

    :))

Leave a Reply