Skip to content

Instantly share code, notes, and snippets.

@mikehale
Created April 13, 2010 15:17
Show Gist options
  • Select an option

  • Save mikehale/364717 to your computer and use it in GitHub Desktop.

Select an option

Save mikehale/364717 to your computer and use it in GitHub Desktop.
Lightweight delayed job (for use by cron)
module Jobs
class HelloWorld < Struct.new(:text)
def perform
Rails.logger.debug text
Rails.logger.debug "sleeping for 7 seconds"
sleep(7)
end
end
end
__END__
require 'rubygems'
require 'active_record'
require 'yaml'
require 'delayed_job'
Delayed::Worker.backend = :active_record
dbconfig = YAML::load(File.open('config/database.yml'))["development"]
ActiveRecord::Base.establish_connection(dbconfig)
$LOAD_PATH << "app/models"
require 'jobs/failure_notified_perform'
Dir["app/models/jobs/*"].each do |job|
require job
end
Delayed::Job.enqueue(Jobs::HelloWorld.new("Hi Adam!"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment