Class: WorkflowRb::Db::ActiveRecordPersistenceProvider
- Inherits:
-
Object
- Object
- WorkflowRb::Db::ActiveRecordPersistenceProvider
- Defined in:
- lib/workflow_rb/db/active_record_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 ⇒ ActiveRecordPersistenceProvider
constructor
A new instance of ActiveRecordPersistenceProvider.
- #persist_workflow(workflow) ⇒ Object
- #remove_unpublished_event(id) ⇒ Object
- #terminate_subscription(id) ⇒ Object
Constructor Details
#initialize ⇒ ActiveRecordPersistenceProvider
Returns a new instance of ActiveRecordPersistenceProvider.
8 9 |
# File 'lib/workflow_rb/db/active_record_persistence_provider.rb', line 8 def initialize end |
Instance Method Details
#create_new_workflow(workflow) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/workflow_rb/db/active_record_persistence_provider.rb', line 11 def create_new_workflow(workflow) rec = WorkflowRb::Db::WorkflowInstance.new rec.pack(workflow) rec.save! workflow.id = rec.id rec.id end |
#create_subscription(subscription) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/workflow_rb/db/active_record_persistence_provider.rb', line 42 def create_subscription(subscription) rec = WorkflowRb::Db::EventSubscription.new rec.pack(subscription) rec.save! subscription.id = rec.id rec.id end |
#create_unpublished_event(pub) ⇒ Object
60 61 62 63 64 |
# File 'lib/workflow_rb/db/active_record_persistence_provider.rb', line 60 def create_unpublished_event(pub) rec = WorkflowRb::Db::EventPublication.new rec.pack(pub) rec.save! end |
#get_runnable_instances ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/workflow_rb/db/active_record_persistence_provider.rb', line 30 def get_runnable_instances result = [] next_execution = WorkflowRb::Db::WorkflowInstance.arel_table[:next_execution] WorkflowRb::Db::WorkflowInstance .where(status: WorkflowStatus::RUNNABLE) .where(next_execution.lteq(Time.now)) .find_each do |wf| result << wf.unpack.id end result end |
#get_subscriptions(event_name, event_key) ⇒ Object
50 51 52 53 54 |
# File 'lib/workflow_rb/db/active_record_persistence_provider.rb', line 50 def get_subscriptions(event_name, event_key) WorkflowRb::Db::EventSubscription .where(event_name: event_name) .where(event_key: event_key) end |
#get_unpublished_events ⇒ Object
70 71 72 |
# File 'lib/workflow_rb/db/active_record_persistence_provider.rb', line 70 def get_unpublished_events WorkflowRb::Db::EventPublication.all end |
#get_workflow_instance(id) ⇒ Object
25 26 27 28 |
# File 'lib/workflow_rb/db/active_record_persistence_provider.rb', line 25 def get_workflow_instance(id) rec = WorkflowRb::Db::WorkflowInstance.find(id) rec.unpack end |
#persist_workflow(workflow) ⇒ Object
19 20 21 22 23 |
# File 'lib/workflow_rb/db/active_record_persistence_provider.rb', line 19 def persist_workflow(workflow) existing = WorkflowRb::Db::WorkflowInstance.find(workflow.id) existing.pack(workflow) existing.save! end |
#remove_unpublished_event(id) ⇒ Object
66 67 68 |
# File 'lib/workflow_rb/db/active_record_persistence_provider.rb', line 66 def remove_unpublished_event(id) WorkflowRb::Db::EventPublication.delete(id) end |
#terminate_subscription(id) ⇒ Object
56 57 58 |
# File 'lib/workflow_rb/db/active_record_persistence_provider.rb', line 56 def terminate_subscription(id) WorkflowRb::Db::EventSubscription.delete(id) end |