27. cron-like
- every 3 hours...
- the first of each month...
- on Tuesdays...
- when the world ends...
http://www.flickr.com/photos/spine/2408967576/
28. Job example
apps/jobs/my_job.rb
class MyJob
def run()
# your code here
end
end
35. Let’s go!
arbitrary_app_stuff.rb
class MyController < ApplicationController
include TorqueBox::Injectors
def index
@queue = inject( ‘/queues/puppies’ )
@queue.publish( “Oh, puppies!” )
end
end
36. Now arriving...
app/processors/my_processor
include TorqueBox::Messaging
class MyProcessor < MessageProcessor
def initialize(opts)
end
def on_message(body)
# your code here.
end
end
42. Enabling
my_arbitrary_file.rb
class User
include TorqueBox::Messaging::Backgroundable
def do_something_slowly()
upload_over_300baud_modem()
end
end
44. Using explicitly
my_other_arbitrary_file.rb
u = User.new
u.do_something_slowly()
u.background.do_something_slowly()
45. Forcing
my_arbitrary_file.rb
class User
include TorqueBox::Messaging::Backgroundable
always_background :do_something_slowly
def do_something_slowly()
upload_over_300baud_modem()
end
end
46. Using implicitly
my_other_arbitrary_file.rb
u = User.new
u.do_something_slowly()
47. The FUTURE!
future = user.do_something_slowly()
future.started?
future.complete?
future.error?
future.result
48. Progress!
class User
include TorqueBox::Backgroundable
always_background :do_something_slowly
def do_something_slowly
upload_over_modem()
future.status = “uploaded”
alert_authorities
future.status = “alerted”
end
end
53. XA
Everything succeeds or everything fails
‣ HornetQ supports XA
‣ Infinispan supports XA
‣ TorqueBox makes ActiveRecord
support XA, if your database does.
67. Example Stomplet
app/stomplets/my_stomplet.rb
class MyStomplet
def on_subscribe(subscriber)
end
def on_unsubscribe(subscriber)
end
def on_message(stomp_message, session)
end
end