Sha256: 9f6ef991f44d7dbd82776acab873f5a7ab77da8297088ce68d143d2b81a54c61

Contents?: true

Size: 555 Bytes

Versions: 2

Compression:

Stored size: 555 Bytes

Contents

class MigrateHandlerToPayloadOnDelayedJobs < ActiveRecord::Migration<%= migration_version %>
  class DelayedJob < ActiveRecord::Base
  end

  def up
    DelayedJob.find_each do |job|
      loaded = YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(job.handler) : YAML.load(job.handler)
      job.update_columns(payload: loaded.job_data)
    end
  end

  def down
    DelayedJob.find_each do |job|
      handler = ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper.new(job.payload).to_yaml
      job.update_columns(handler: handler)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
delayed_job_json-1.0.1 lib/generators/delayed_job_json/templates/migration2.rb
delayed_job_json-1.0.0 lib/generators/delayed_job_json/templates/migration2.rb