Skip to content

Instantly share code, notes, and snippets.

@russ
Created October 3, 2011 22:34
Show Gist options
  • Save russ/1260445 to your computer and use it in GitHub Desktop.
Save russ/1260445 to your computer and use it in GitHub Desktop.
class Queue
@@jobs = []
def self.enqueue(klass, *arguments)
@@jobs << { :class => klass, :arguments => arguments }
end
def self.work
while job = @@jobs.shift
puts job[:class].perform(*job[:arguments])
end
end
end
class MyJob
def self.perform(numbers)
numbers.reduce(:+)
end
end
Queue.enqueue(MyJob, [ 1, 2, 3, 4, 5 ])
Queue.enqueue(MyJob, [ 6, 7, 8, 9, 10 ])
Queue.work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment