Skip to content

Instantly share code, notes, and snippets.

@mediocretes
Created February 8, 2011 15:34
Show Gist options
  • Save mediocretes/816591 to your computer and use it in GitHub Desktop.
Save mediocretes/816591 to your computer and use it in GitHub Desktop.
class Simulation < ActiveRecord::Base
@queue = :simulation
@unique_jobs = true
@delayed_jobs = true
def simulate
Resque.enable_delay(:simulation) #call this elsewhere in a production app
Resque.enqueue(Simulation, {:_id => self.id, :delay_until => Time.now + 1800})
end
def self.perform(options)
sim = Simulation.find options['id']
sim.actually_simulate
end
def actually_simulate
sleep 5
self.results = rand 100 + 1
save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment