Archive for the ‘Ruby’ Category

When the custom rake task to migrate data from one system to another was implemented our cron job stopped working.

It looked like it was trying to execute the contents of the custom rake file every time a call to rake -f Rakefile was made.

The problem ended up being Redmine’s Rakefile was set to include all defined task in a {root}/lib/tasks directory. Anything not in a namespace was executing regardless of the rake task called.

Custom rake task

# code here executes all the time
puts 'I execute ever time rake -f Rakefile RAILS_ENV="{env}" is executed'

namespace :redmine do
  desc "Migrate from RT3 to Redmine"
  task :a_task  => :environment do
    # code here only executes when it's called
    puts 'I execute only when my namespace:task is invoked rake -f Rakefile redmine:a_task RAILS_ENV="{env}" is executed'

Redmine’s Rakefile

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/switchtower.rake, and they will automatically be available to Rake.

require(File.join(File.dirname(__FILE__), 'config', 'boot'))

require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

require 'tasks/rails'

Read Full Post »

I wanted to iterate over an active record in batches. Found a great example but for my needs I wanted to walk backwards over the batch.

Needless to say it’s not possible. I don’t mind find_each limited to the id field, but DESC would be nice.

model.find_each(:batch_size => 200, :order => "DESC") do |instance|
  puts instance.inspect
# => You can't specify an order, it's forced to be model.id ASC

Read Full Post »

The last two weeks have been focused on learning ruby to write a rake task that would migrate data from Perl based Request Tracker(TM) to a RoR based Redmine issue tracking system.

I’m happy to report (and sad I didn’t post incremental updates on my experiences with ruby) that I have released a beta rake task that goes 90% of the way.


Needless to say there are countless ways this could be improved and cleaned up. I hope that others find it useful, and I am happy to have ‘contributed’ back to the community for once.

My summary of RoR is its nice to be working in a class based, object based MVC architecture. Don’t know if 4D will ever get there.

Read Full Post »

%d bloggers like this: