README.md in cloudist-0.0.3 vs README.md in cloudist-0.1.0
- old
+ new
@@ -37,45 +37,68 @@
This will start and AMQP connection and EM loop then yield everything inside it.
In your worker:
- Cloudist.worker {
- job('make.sandwich') {
- # Make sandwich here
-
- # Your worker has access to the data sent from the server in the 'data' attribute
- data # => {:bread => "white", :sauce => 'bbq'}
-
- # Fire the finished event
- finished!
+ Cloudist.start {
+ log.info("Started Worker")
+
+ worker {
+ job('make.sandwich') {
+ log.info("JOB (#{id}) Make sandwich with #{data[:bread]} bread")
+ log.debug(data.inspect)
+
+ # Do long running tasks here
+ EM.defer {
+ progress(0)
+ started!
+ progress(10)
+ sleep(1)
+ progress(20)
+ sleep(5)
+ progress(90)
+ sleep(1)
+ finished!
+ progress(100)
+ }
+ }
}
}
In your application:
-
- job = Cloudist.enqueue('make.sandwich', :bread => "white", :sauce => 'bbq')
- Cloudist.listen(job) {
- event('finished') {
- # Called when we finish making a sandwich
+ Cloudist.start {
+ # Enqueue sandwich job
+ log.info("Dispatching sandwich making job...")
+ enqueue('make.sandwich', {:bread => 'white'})
+
+ # Listen to all sandwich jobs
+ listen('make.sandwich') {
+ progress {
+ Cloudist.log.info("Progress: #{data[:progress]}")
+ }
+
+ event('started') {
+ Cloudist.log.info("Started making sandwich at #{Time.now.to_s}")
+ }
+
+ event('finished'){
+ Cloudist.log.info("Finished making sandwich at #{Time.now.to_s}")
+ }
}
+
}
-
-You don't need to listen to responses immediately, if you store the job_id you can listen to responses at any time in the near future.
-You can also queue jobs outside an EventMachine loop using Cloudist.enqueue but this will be very slow as it has to connect to your message queue first.
+If your application provides an AMQP.start loop already, you can skip the Cloudist.start
Acknowledgements
-------
Portions of this gem are based on code from the following projects:
- Heroku's Droid gem
- Lizzy
- Minion
-- Nanite
-- Smith
Contributing to Cloudist
------------------------
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet