Class: Ruote::Synchronize::Broker
- Inherits:
-
Object
- Object
- Ruote::Synchronize::Broker
- Includes:
- ReceiverMixin
- Defined in:
- lib/ruote/synchronize/broker.rb
Overview
A Ruote Receiver that act as a broker between two processes.
It will store workitems under the synchronize
storage type.
Instance Method Summary collapse
-
#initialize(context) ⇒ Broker
constructor
A new instance of Broker.
-
#publish(key, workitem) ⇒ true, false
Check if there was a previous workitem stored with the same key.
-
#unpublish(key) ⇒ void
Deletes a previously stored key from storage.
Constructor Details
#initialize(context) ⇒ Broker
Returns a new instance of Broker.
13 14 15 |
# File 'lib/ruote/synchronize/broker.rb', line 13 def initialize(context) @context = context end |
Instance Method Details
#publish(key, workitem) ⇒ true, false
Check if there was a previous workitem stored with the same key. If so, receives and deletes the stored workitem. Else, stores the workitem with the key.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ruote/synchronize/broker.rb', line 24 def publish(key, workitem) if doc = stored_doc_from_key(key) # another process already registered the same key # allow both processes to continue continue_with doc true else # this process is the first to register # store the workitem for now wait_for key, workitem false end end |
#unpublish(key) ⇒ void
This method returns an undefined value.
Deletes a previously stored key from storage
43 44 45 46 |
# File 'lib/ruote/synchronize/broker.rb', line 43 def unpublish(key) doc = stored_doc_from_key(key) @context.storage.delete(doc) if doc end |