-
Add
gem 'delayed_job', '2.1.4'
to your Gemfile -
Run
bundle install
-
Run
rails g migration create_delayed_jobs
-
Edit the created migration to contain:
class CreateDelayedJobs < ActiveRecord::Migration def self.up create_table :delayed_jobs, :force => true do |table| table.integer :priority, :default => 0 # jobs can jump to the front of table.integer :attempts, :default => 0 # retries, but still fail eventually table.text :handler # YAML object dump table.text :last_error # last failure table.datetime :run_at # schedule for later table.datetime :locked_at # set when client working this job table.datetime :failed_at # set when all retries have failed table.text :locked_by # who is working on this object table.timestamps end end def self.down drop_table :delayed_jobs end end
-
Create delayed_tasks.rake in lib/tasks, see example bellow for spree_solr_search tasks
Created
March 28, 2011 09:50
-
-
Save romul/890215 to your computer and use it in GitHub Desktop.
Running rake tasks in background
This file contains 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
class DelayedRakeTask | |
def initialize(task_name) | |
@task_name = task_name | |
end | |
def perform | |
Rake::Task[@task_name].invoke | |
end | |
end | |
namespace :solr do | |
namespace :async do | |
task :reindex => :environment do | |
Delayed::Job.enqueue DelayedRakeTask.new('solr:reindex') | |
end | |
task :optimize => :environment do | |
Delayed::Job.enqueue DelayedRakeTask.new('solr:optimize') | |
end | |
end | |
end |
bundle exec rake jobs:work
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to start delayed job in development ?