Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[Patch] Add beep sound when rake task fails because of pending migrations

#3384

Background:

When running e.g. tests that take a few minutes, most users (or is it only me?) use rake db:migrate and then do something else. In a bigger project it is quite common that fetching the latest changes from git added a new migration file.

Because the console is in the background often times the user doesn't know that the migrations haven't been applied yet and time is wasted. A default error/warn sound could help notify the user that there's a problem.

The attached patch is tiny and basically just adds the beep character to the error message.

Reported by Dennis Theisen · October 16th, 2009 @ 06:45 PM

State: invalid
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Dennis Theisen
  2. Lenary
    Lenary

    Something clever about rake is that when you do something that in any other rails item (say a method) would be redefining it, instead rake appends this action onto the rake task. this is how you could accomplish this.

    Here shows what i mean by what i said in that first sentence:

    task :foo do
      puts "bar"
    end
    
    task :foo do
      puts "baz"
    end
    

    when you run it, this happens:

    ⚡ rake foo
    (in ~/Git/rails-three/tester)
    bar
    baz
    

    I think that this is probably bloat for core rails, but i have done a little hacking and here's a snippet for your Rakefile (didn't work in a lib/tasks/*.rake file during my testing sadly)

    task :plink_on_abort do
      def abort(string=nil)
        $stderr.print "\a"
        super
      end
    end
    if Rake::Task.task_defined?("db:abort_if_pending_migrations")
      Rake::Task["db:abort_if_pending_migrations"].prerequisites << "plink_on_abort" 
    end
    

    -1

    April 18th, 2010 @ 12:29 AM

  3. Lenary
    Lenary

    My last comment was a little unclear. Usually the first method works, but not in this case when your addition is in the middle of lots of logic. Hence Why i showed you that snippet. If you wanted to have an even more simple solution, for it to plink on every abort, just redefine abort as i have, but at the top level in the Rakefile.

    April 18th, 2010 @ 12:35 AM

  4. Dennis Theisen
    Dennis Theisen

    Thanks for your help!
    I realized it's really not a good idea to patch something like this into rails core. You can mark this ticket as invalid.

    I actually found a neat way of solving this problem (getting notified when rake tasks are finished) with the rakegrowl gem:

    http://github.com/porras/rakegrowl

    April 18th, 2010 @ 01:52 AM

  5. Rizwan Reza
    Rizwan Reza
    • State changed from new to invalid

    May 15th, 2010 @ 03:07 PM

  6. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    October 9th, 2010 @ 09:48 PM