Setting up Background Job (BJ) Properly

June 23rd, 2008

I dealt with a customer today who was a bit miffed that his Background Jobtasks were taking a while to kick off after the Rails app submitted them to the queue.

I dug a little deeper into the problem - he was using our standard configuration, moving control of the runner out to cron instead of being controlled from within the app itself.

1
Bj.config["production.no_tickle"] = true

and then a cronjob such as

*/2 * * * * bj run --forever --rails_env=production --rails_root=/data/user/current

Read the rest of this entry 0 comments »

Standardise flash messages across your app

July 19th, 2007 In the admin areas of apps I have been writing recently I've found myself writing the same block of code over and over. In these pretty mundane admin areas, after any action has completed or a rescue block has been triggered for ActiveRecord::RecordNotFound I like to show a quick "XXXXX Record Created" /"Could not find XXX with that ID" and then redirect people back to a safe place.

To solve my problem I created a double team-up of TextMate snippets and an addition to ActionController to make my coding quicker, and to standardise these messages across the whole app.

Read the rest of this entry


Ruby: Require everything in a directory

July 3rd, 2007 Recently I've been working a lot with the Liquid templating system and in our application initialisation we needed to quickly require all the files in a particular directory that aren't in the normal rails load path. Normally a good way to do this is to just add the new paths onto your Rails load path


$LOAD_PATH << File.join(File.dirname(__FILE__), '../app/drops')

or, in environment.rb

config.load_paths += %W( #{RAILS_ROOT}/app/drops #{RAILS_ROOT}/app/filters )

This particular app uses engines so most of the configuration resides in our core plugin in order not to dirty up environment.rb and make is easier to keep all the configuration centrally managed. This means we can't really touch environment.rb or anything in the Rails initializer block for that matter.
Then I discovered the power of .glob


Dir.glob(File.join(File.dirname(__FILE__), '../app/drops/*.rb')).each {|f| require f }

Perfect.

Edited: Yes - that second snippet of code is from Mephisto - at the moment it's the best reference for how to implement a liquid based templating system. Thanks Rick, you've really helped us out!