public
Last active

Gist for Kthxbye readme

  • Download Gist
kthxbye_job.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# dummy job class
class MyJob
def self.perform(data)
puts "Do something with #{data}"
data.gsub(/hello/i, "Goodbye")
end
end
 
# setup options, then connect
Kthxbye::Config.setup(:redis_server => 'localhost', :redis_port => 8080)
Kthxbye.connect
 
# each enqueued job returns a unique id to poll with
unique_id = Kthxbye.enqueue("jobs", MyJob, "Hello World")
 
# ... code code code ...
 
# polls queue every 5 seconds
computed_value = Kthxbye.poll("jobs", unique_id, 5)
kthxbye_worker.rb
Ruby
1 2 3 4 5
# inits with queue
worker = Kthxbye::Worker.new("jobs")
 
# connects to queue and runs jobs found there
worker.run

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.