RakeUI – a Rails 3.1 Engine that provides a web UI for Rake tasks built with Node.js and Socket.io

by rbrant on December 21, 2011

I’ve been determined to find a reason to use Node.js in a project since, as the adage goes, you have to sart somewhere. What I came up with was something that I’m actually going to use in future projects, I think.

I’ve often wished there were an easy way to give clients access to rake tasks, but in the browser. Rake tasks are great because you can provide real time feedback in the terminal to show the user what’s going on as it’s happening. Node.js along with Socket.io make creating this experience in the browser really easy.

This project is a Rails 3.1 engine, so it’s super easy to hook up in your Rails application. Aside from using Rails 3.1+, you need to have Node.js and Socket.io installed. So to get this running:

In your Gemfile:

gem 'rake_ui', :git => "git://github.com/rbrant/rake_ui.git"

In your routes.rb file:

Rails.application.routes.draw do  
  mount RakeUi::Engine => "/rake_ui"
end

Then you need to start the Node server. From your app’s root:

rake app:start_node_server

Once your Rails app is started, visit /rake_ui to see your rake tasks. All stdout generated in your task via something like:

$stdout.puts "hey now"

will be displayed in the black window to the right of the Rake task command listing.

They way it works is that when the app is initialized, all the available rake tasks are stored in memory along with an ID key. The index page displays all he rake tasks and identifies them by their ID. When a task is selected, it get identified and then called via:

Kernel.system("#{@rake_task.command} #{@rake_task.arguments} &> #{Rails.root}/log/rake.log")

As you can see, stdout is sent to a log file. This log file gets tailed by Node and hooked up to the browser via Socket.io. Very cool, eh? I need to find a real node project..

To make this engine truly useful, I’ll probably add a way to blacklist certain tasks so they aren’t available in the UI. Probably not a good idea to allow your clients to drop their database. I also need to scrub the optional arguments.

The project is available on Github:

https://github.com/rbrant/rake_ui

{ 1 trackback }

ROR - Parts - Engines | Pearltrees
February 13, 2012 at 11:17 am

{ 0 comments… add one now }

Leave a Comment

Previous post: