workflow_rb-db 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +58 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/workflow_rb/db.rb +9 -0
- data/lib/workflow_rb/db/active_record_persistence_provider.rb +74 -0
- data/lib/workflow_rb/db/entities.rb +102 -0
- data/lib/workflow_rb/db/migrate/001_schema.rb +50 -0
- data/lib/workflow_rb/db/version.rb +5 -0
- data/workflow_rb-db.gemspec +28 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3a8dcf80c3de7c40b7ea88d0c6f8990cab652620
|
4
|
+
data.tar.gz: fd2f68273b331129c87e9e68ba7e0ce047eafa82
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e9d355c503f6b51bddd1f9e34cde9e1b19ddaba14bca1a414a3b80941f5ea62c86693320a694f3821edbbabe6658a08fb547ce6a256d9d21b7b176a3ccefd1f6
|
7
|
+
data.tar.gz: abf764c16a0755f86d18a9a8768b31e73a9739dbbb508399d0e5b4248be7e072009a1b81bc312ec6195057c0977d70901a55ef9ee3e231a30874342677153daf
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# WorkflowRb::Db
|
2
|
+
|
3
|
+
Provides support to persist workflows running on WorkflowRb to a database supported by Active Record.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'workflow_rb-db'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install workflow_rb-db
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Setup a database.yml config file with a "workflow" section
|
24
|
+
|
25
|
+
```yaml
|
26
|
+
workflow:
|
27
|
+
adapter: postgresql
|
28
|
+
encoding: unicode
|
29
|
+
database: workflow_rb
|
30
|
+
pool: 12
|
31
|
+
username: postgres
|
32
|
+
password: password
|
33
|
+
host: localhost
|
34
|
+
port: 5432
|
35
|
+
```
|
36
|
+
|
37
|
+
Add the tables to your database
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
db_config = YAML.load_file('database.yml')
|
41
|
+
ActiveRecord::Base.establish_connection(db_config['workflow'])
|
42
|
+
schema = WorkflowRb::Db::Schema.new
|
43
|
+
schema.up
|
44
|
+
```
|
45
|
+
|
46
|
+
Use the *.use_persistence* method on the *WorkflowHost* to configure it to use the ActiveRecord provider
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
require 'workflow_rb/db'
|
50
|
+
require 'yaml'
|
51
|
+
|
52
|
+
db_config = YAML.load_file('database.yml')
|
53
|
+
WorkflowRb::Db::WorkflowRecord.establish_connection(db_config['workflow'])
|
54
|
+
|
55
|
+
# create host
|
56
|
+
host = WorkflowRb::WorkflowHost.new
|
57
|
+
host.use_persistence(WorkflowRb::Db::ActiveRecordPersistenceProvider.new)
|
58
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "workflow_rb/db"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'workflow_rb'
|
2
|
+
require 'workflow_rb/db/entities'
|
3
|
+
|
4
|
+
module WorkflowRb
|
5
|
+
module Db
|
6
|
+
class ActiveRecordPersistenceProvider
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_new_workflow(workflow)
|
12
|
+
rec = WorkflowRb::Db::WorkflowInstance.new
|
13
|
+
rec.pack(workflow)
|
14
|
+
rec.save!
|
15
|
+
rec.id
|
16
|
+
end
|
17
|
+
|
18
|
+
def persist_workflow(workflow)
|
19
|
+
existing = WorkflowRb::Db::WorkflowInstance.find(workflow.id)
|
20
|
+
existing.pack(workflow)
|
21
|
+
existing.save!
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_workflow_instance(id)
|
25
|
+
rec = WorkflowRb::Db::WorkflowInstance.find(id)
|
26
|
+
rec.unpack
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_runnable_instances
|
30
|
+
result = []
|
31
|
+
next_execution = WorkflowRb::Db::WorkflowInstance.arel_table[:next_execution]
|
32
|
+
WorkflowRb::Db::WorkflowInstance
|
33
|
+
.where(status: WorkflowStatus::RUNNABLE)
|
34
|
+
.where(next_execution.lteq(Time.now))
|
35
|
+
.find_each do |wf|
|
36
|
+
result << wf.unpack.id
|
37
|
+
end
|
38
|
+
result
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_subscription(subscription)
|
42
|
+
rec = WorkflowRb::Db::EventSubscription.new
|
43
|
+
rec.pack(subscription)
|
44
|
+
rec.save!
|
45
|
+
rec.id
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_subscriptions(event_name, event_key)
|
49
|
+
WorkflowRb::Db::EventSubscription
|
50
|
+
.where(event_name: event_name)
|
51
|
+
.where(event_key: event_key)
|
52
|
+
end
|
53
|
+
|
54
|
+
def terminate_subscription(id)
|
55
|
+
WorkflowRb::Db::EventSubscription.delete(id)
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_unpublished_event(pub)
|
59
|
+
rec = WorkflowRb::Db::EventPublication.new
|
60
|
+
rec.pack(pub)
|
61
|
+
rec.save!
|
62
|
+
end
|
63
|
+
|
64
|
+
def remove_unpublished_event(id)
|
65
|
+
WorkflowRb::Db::EventPublication.delete(id)
|
66
|
+
end
|
67
|
+
|
68
|
+
def get_unpublished_events
|
69
|
+
WorkflowRb::Db::EventPublication.all
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require "active_record"
|
2
|
+
require "yaml"
|
3
|
+
require "workflow_rb"
|
4
|
+
|
5
|
+
module WorkflowRb
|
6
|
+
module Db
|
7
|
+
class WorkflowRecord < ActiveRecord::Base
|
8
|
+
def self.abstract_class?
|
9
|
+
true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class WorkflowInstance < WorkflowRecord
|
14
|
+
def self.abstract_class?
|
15
|
+
false
|
16
|
+
end
|
17
|
+
|
18
|
+
def pack(workflow)
|
19
|
+
# self.id = workflow.id
|
20
|
+
self.definition_id = workflow.definition_id
|
21
|
+
self.version = workflow.version
|
22
|
+
self.description = workflow.description
|
23
|
+
self.next_execution = workflow.next_execution
|
24
|
+
self.status = workflow.status
|
25
|
+
self.create_time = workflow.create_time
|
26
|
+
self.complete_time = workflow.complete_time
|
27
|
+
self.data = YAML.dump(workflow.data)
|
28
|
+
self.execution_pointers = YAML.dump(workflow.execution_pointers)
|
29
|
+
end
|
30
|
+
|
31
|
+
def unpack
|
32
|
+
result = WorkflowRb::WorkflowInstance.new
|
33
|
+
result.id = self.id
|
34
|
+
result.definition_id = self.definition_id
|
35
|
+
result.version = self.version
|
36
|
+
result.description = self.description
|
37
|
+
result.next_execution = self.next_execution
|
38
|
+
result.status = self.status
|
39
|
+
result.create_time = self.create_time
|
40
|
+
result.complete_time = self.complete_time
|
41
|
+
result.data = YAML.load(self.data)
|
42
|
+
result.execution_pointers = YAML.load(self.execution_pointers)
|
43
|
+
|
44
|
+
result
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
class EventSubscription < WorkflowRecord
|
50
|
+
def self.abstract_class?
|
51
|
+
false
|
52
|
+
end
|
53
|
+
|
54
|
+
def pack(sub)
|
55
|
+
self.workflow_id = sub.workflow_id
|
56
|
+
self.step_id = sub.step_id
|
57
|
+
self.event_name = sub.event_name
|
58
|
+
self.event_key = sub.event_key
|
59
|
+
end
|
60
|
+
|
61
|
+
def unpack
|
62
|
+
result = WorkflowRb::EventSubscription.new
|
63
|
+
result.id = self.id
|
64
|
+
result.workflow_id = self.workflow_id
|
65
|
+
result.step_id = self.step_id
|
66
|
+
result.event_name = self.event_name
|
67
|
+
result.event_key = self.event_key
|
68
|
+
result
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
class EventPublication < WorkflowRecord
|
74
|
+
def self.abstract_class?
|
75
|
+
false
|
76
|
+
end
|
77
|
+
|
78
|
+
def pack(pub)
|
79
|
+
self.workflow_id = pub.workflow_id
|
80
|
+
self.step_id = pub.step_id
|
81
|
+
self.event_name = pub.event_name
|
82
|
+
self.event_key = pub.event_key
|
83
|
+
self.event_data = YAML.dump(pub.event_data)
|
84
|
+
end
|
85
|
+
|
86
|
+
def unpack
|
87
|
+
result = WorkflowRb::EventPublication.new
|
88
|
+
result.id = self.id
|
89
|
+
result.workflow_id = self.workflow_id
|
90
|
+
result.step_id = self.step_id
|
91
|
+
result.event_name = self.event_name
|
92
|
+
result.event_key = self.event_key
|
93
|
+
result.event_data = YAML.load(self.event_data)
|
94
|
+
result
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "active_record"
|
2
|
+
|
3
|
+
module WorkflowRb
|
4
|
+
module Db
|
5
|
+
class Schema < ActiveRecord::Migration
|
6
|
+
def up
|
7
|
+
create_table :workflow_instances, force: true do |t|
|
8
|
+
t.string :definition_id, :limit => 100
|
9
|
+
t.integer :version
|
10
|
+
t.string :description
|
11
|
+
t.string :execution_pointers
|
12
|
+
t.datetime :next_execution
|
13
|
+
t.integer :status
|
14
|
+
t.string :data
|
15
|
+
t.datetime :create_time
|
16
|
+
t.datetime :complete_time
|
17
|
+
t.integer :lock_version
|
18
|
+
|
19
|
+
t.index :next_execution
|
20
|
+
t.index :status
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
create_table :event_subscriptions, force: true do |t|
|
25
|
+
t.integer :workflow_id
|
26
|
+
t.integer :step_id
|
27
|
+
t.string :event_name, :limit => 100
|
28
|
+
t.string :event_key, :limit => 100
|
29
|
+
|
30
|
+
t.index :event_name
|
31
|
+
t.index :event_key
|
32
|
+
end
|
33
|
+
|
34
|
+
create_table :event_publications, force: true do |t|
|
35
|
+
t.integer :workflow_id
|
36
|
+
t.integer :step_id
|
37
|
+
t.string :event_name, :limit => 100
|
38
|
+
t.string :event_key, :limit => 100
|
39
|
+
t.string :event_data
|
40
|
+
|
41
|
+
t.index :event_name
|
42
|
+
t.index :event_key
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'workflow_rb/db/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "workflow_rb-db"
|
8
|
+
spec.version = WorkflowRb::Db::VERSION
|
9
|
+
spec.authors = ["Daniel gerlag"]
|
10
|
+
spec.email = ["daniel@gerlag.ca"]
|
11
|
+
|
12
|
+
spec.summary = %q{Active Record persistence provider for WorkflowRb}
|
13
|
+
spec.homepage = "https://github.com/danielgerlag/workflow_rb"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "workflow_rb", "~> 0.1.0"
|
23
|
+
spec.add_dependency "activerecord", "~> 5.0.0"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: workflow_rb-db
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel gerlag
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: workflow_rb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.13'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.13'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- daniel@gerlag.ca
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- lib/workflow_rb/db.rb
|
99
|
+
- lib/workflow_rb/db/active_record_persistence_provider.rb
|
100
|
+
- lib/workflow_rb/db/entities.rb
|
101
|
+
- lib/workflow_rb/db/migrate/001_schema.rb
|
102
|
+
- lib/workflow_rb/db/version.rb
|
103
|
+
- workflow_rb-db.gemspec
|
104
|
+
homepage: https://github.com/danielgerlag/workflow_rb
|
105
|
+
licenses: []
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.6.7
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Active Record persistence provider for WorkflowRb
|
127
|
+
test_files: []
|