Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Client/server architecture for invoking and running Rake tasks

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 bin
Octocat-spinner-32 lib
Octocat-spinner-32 pkg
Octocat-spinner-32 tasks
Octocat-spinner-32 test
Octocat-spinner-32 tmp
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 TODO
Octocat-spinner-32 VERSION
Octocat-spinner-32 rake_server.gemspec
README.rdoc

RakeServer

What is it?

RakeServer is a lightweight client/server architecture for running Rake tasks. The server is a long-running process that loads tasks from a Rakefile and waits for requests to execute tasks. Each time a task is requested, the server forks, runs the task, and streams the output from the task back to the client.

When the server is started, it can be given tasks to eager-run; this is mainly useful for loading application code into the pre-fork environment.

What's the point?

The main intended use case for RakeServer is to provide a means for production deployments to run Rake tasks in the background (e.g. via a cron) without needing to load the application environment from scratch each time a task is executed. It may also be useful for remote invocation of Rake tasks, but that is not the main goal.

Basic usage

$ cd /path/to/my/rails/app
$ rake-server start environment
$ rake-client db:migrate

Valid commands to rake-server are `start`, `stop`, `run`, and `restart`. Any additional arguments name Rake tasks that should be eagerly run when the server starts. In the above example, we call the `environment` task, which loads the Rails environment for fast invocation of Rails-dependent tasks by the client.

Fork hooks

RakeServer forks a separate process each time the client invokes a task. In a Rails environment, it's necessary to re-connect to ActiveRecord each time the application forks. RakeServer provides pre-fork and post-fork hooks to make this easy.

First, in your Rakefile:

namespace :rake_server

task :fork_hooks RakeServer.before_fork { ActiveRecord::Base.remove_connection } RakeServer.after_fork { ActiveRecord::Base.establish_connection } end

end

Then, when you start the server, specify your fork hooks setup as an eager task:

$ rake-server start environment rake_server:fork_hooks
Something went wrong with that request. Please try again.