Class: WorkflowRb::MemoryPersistenceProvider
- Inherits:
-
Object
- Object
- WorkflowRb::MemoryPersistenceProvider
- Defined in:
- lib/workflow_rb/services/memory_persistence_provider.rb
Instance Method Summary collapse
- #create_new_workflow(workflow) ⇒ Object
- #create_subscription(subscription) ⇒ Object
- #create_unpublished_event(pub) ⇒ Object
- #get_runnable_instances ⇒ Object
- #get_subscriptions(event_name, event_key) ⇒ Object
- #get_unpublished_events ⇒ Object
- #get_workflow_instance(id) ⇒ Object
-
#initialize ⇒ MemoryPersistenceProvider
constructor
A new instance of MemoryPersistenceProvider.
- #persist_workflow(workflow) ⇒ Object
- #remove_unpublished_event(id) ⇒ Object
- #terminate_subscription(id) ⇒ Object
Constructor Details
#initialize ⇒ MemoryPersistenceProvider
Returns a new instance of MemoryPersistenceProvider.
8 9 10 11 12 13 |
# File 'lib/workflow_rb/services/memory_persistence_provider.rb', line 8 def initialize @instances = [] @subscriptions = [] @unpublished_events = [] @semaphore = Mutex.new end |
Instance Method Details
#create_new_workflow(workflow) ⇒ Object
15 16 17 18 19 |
# File 'lib/workflow_rb/services/memory_persistence_provider.rb', line 15 def create_new_workflow(workflow) workflow.id = SecureRandom.uuid @instances << workflow workflow.id end |
#create_subscription(subscription) ⇒ Object
37 38 39 40 41 |
# File 'lib/workflow_rb/services/memory_persistence_provider.rb', line 37 def create_subscription(subscription) subscription.id = SecureRandom.uuid @subscriptions << subscription subscription.id end |
#create_unpublished_event(pub) ⇒ Object
53 54 55 |
# File 'lib/workflow_rb/services/memory_persistence_provider.rb', line 53 def create_unpublished_event(pub) @unpublished_events << pub end |
#get_runnable_instances ⇒ Object
32 33 34 35 |
# File 'lib/workflow_rb/services/memory_persistence_provider.rb', line 32 def get_runnable_instances @instances.select {|item| item.next_execution and (item.next_execution <= Time.new) and (item.status == WorkflowStatus::RUNNABLE)} .map {|item| item.id} end |
#get_subscriptions(event_name, event_key) ⇒ Object
43 44 45 |
# File 'lib/workflow_rb/services/memory_persistence_provider.rb', line 43 def get_subscriptions(event_name, event_key) @subscriptions.select { |sub| sub.event_name == event_name and sub.event_key == event_key } end |
#get_unpublished_events ⇒ Object
61 62 63 |
# File 'lib/workflow_rb/services/memory_persistence_provider.rb', line 61 def get_unpublished_events @unpublished_events end |
#get_workflow_instance(id) ⇒ Object
28 29 30 |
# File 'lib/workflow_rb/services/memory_persistence_provider.rb', line 28 def get_workflow_instance(id) @instances.select {|item| item.id == id}.first end |
#persist_workflow(workflow) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/workflow_rb/services/memory_persistence_provider.rb', line 21 def persist_workflow(workflow) @semaphore.synchronize do @instances.delete_if {|item| item.id == workflow.id } @instances << workflow end end |
#remove_unpublished_event(id) ⇒ Object
57 58 59 |
# File 'lib/workflow_rb/services/memory_persistence_provider.rb', line 57 def remove_unpublished_event(id) @unpublished_events.delete_if { |pub| pub.id == id } end |
#terminate_subscription(id) ⇒ Object
47 48 49 50 51 |
# File 'lib/workflow_rb/services/memory_persistence_provider.rb', line 47 def terminate_subscription(id) @semaphore.synchronize do @subscriptions.delete_if { |sub| sub.id == id } end end |