Created
August 27, 2010 01:12
-
-
Save jsmpereira/552575 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_record' | |
# Migrating from http://github.com/tobi/delayed_job to http://github.com/collectiveidea/delayed_job | |
# and with some jobs pending resulted in execution failure due to handler format incompatibility. | |
# | |
# This rake task loops through your delayed_jobs table and updates the handler of each job to comply with | |
# collectiveidea's delayed_job. | |
# | |
# Hope this can be useful to someone. | |
# | |
# Convert | |
# | |
# http://github.com/tobi/delayed_job | |
# Job handler format: | |
# | |
# --- !ruby/struct:Delayed::PerformableMethod | |
# object: CLASS:Notifier | |
# method: :deliver_activation_confirmation | |
# args: | |
# - AR:User:20 | |
# | |
# to | |
# | |
# http://github.com/collectiveidea/delayed_job | |
# Job handler format: | |
# | |
# --- !ruby/struct:Delayed::PerformableMethod | |
# object: !ruby/class Notifier | |
# method: :deliver_activation_confirmation | |
# args: !ruby/ActiveRecord:User | |
# attributes: | |
# id: "20" | |
# created_at: 2009-04-03 01:12:28 | |
# state: active | |
# etc ... | |
namespace :dj_migrate_format do | |
task :start_task => :environment do | |
Delayed::Job.all.each do |job| | |
handler_yaml = YAML.load(job.handler) | |
object = handler_yaml[:object].split(":")[1].constantize | |
method = handler_yaml[:method] | |
args_model = handler_yaml[:args].first.split(":")[1] | |
args_id = handler_yaml[:args].first.split(":")[2] | |
args = args_model.constantize.find args_id | |
new_handler = Delayed::PerformableMethod.new object, method, args | |
new_handler_yaml = new_handler.to_yaml | |
job.handler = new_handler_yaml | |
job.save | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment