Rake provide an easy to use task execution mechanism, but it also has some useful logic for extending existing tasks. Here are a few examples of the kinds of Rake tasks I've been using to make my life easier.
Chaining Tasks
It's possible for one task to call another, but it's also possible for this to go between namespaces:
Running $ rake db:environment
will invoke both the db:environment
and environment
tasks.
We use this to integrate with other task libraries, e.g. ActiveRecord.
Stateful Tasks
Sometimes it's useful to have stateful tasks:
Running $ rake verbose deploy
will print out more detailed information.
We use this when running tasks as background jobs - verbose is not defined unless we want extra output for debugging.
Stateful Pipelines
You can use this to make flexible filters and tasks which can be configured to do different things:
We use tasks like these to export data for customers - we almost always have some specific requirements - but we can usually chain together a set of existing tasks to get the desired output.
Multiple Tasks
It's possible to define multiple tasks with the same name. This is useful if you want to combine multiple files containing tasks
Running $ rake deploy
will invoke both tasks.
We use this to keep our .rake
files simple, focused and organised.
Comments
Leave a comment
Please note, comments must be formatted using Markdown. Links can be enclosed in angle brackets, e.g.
<www.codeotaku.com>
.