libis-workflow-activerecord 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Rakefile +3 -0
- data/db/migrate/003_create_work_items_table.rb +4 -10
- data/db/migrate/004_create_statuses_table.rb +22 -0
- data/db/schema.rb +16 -8
- data/lib/libis/workflow/activerecord.rb +1 -0
- data/lib/libis/workflow/activerecord/config.rb +2 -0
- data/lib/libis/workflow/activerecord/helpers/symbol_serializer.rb +21 -0
- data/lib/libis/workflow/activerecord/status.rb +22 -0
- data/lib/libis/workflow/activerecord/version.rb +1 -1
- data/lib/libis/workflow/activerecord/work_item.rb +27 -6
- data/lib/libis/workflow/activerecord/workflow.rb +2 -0
- data/libis-workflow-activerecord.gemspec +2 -0
- data/spec/spec_helper.rb +12 -7
- data/spec/workflow_spec.rb +5 -1
- data/spec/workitem_spec.rb +2 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 379a7d33367283bc65ca129d9824af1e486e335e308481b702451f4c0dd2dec5
|
4
|
+
data.tar.gz: cf40df8e08387af400220bb24ac5f107540e5a00a3cf650a6f538c7260e8d6ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e31730b7390994d48673e1cbf358f62d4b2d05df8b7cf18c4d020cf25f94ba8f16c2a9ee41dea80db338457dfa8e63eb5d70237ae3694ca067c2f6d54f553380
|
7
|
+
data.tar.gz: a257bdf9e2bbe84a97e3114880307f2f38bb63217484443771cec173343cbd9465d57aedd76d29a3dc83c41df0e6796aa67b70b4b5c84b80f3dc0ccf73434546
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# noinspection RubyResolve
|
1
2
|
require 'bundler/gem_tasks'
|
2
3
|
require 'rspec/core/rake_task'
|
3
4
|
|
@@ -6,7 +7,9 @@ RSpec::Core::RakeTask.new('spec')
|
|
6
7
|
desc 'run tests'
|
7
8
|
task :default => :spec
|
8
9
|
|
10
|
+
# noinspection RubyResolve
|
9
11
|
require 'yaml'
|
12
|
+
# noinspection RubyResolve
|
10
13
|
require 'logger'
|
11
14
|
require 'active_record'
|
12
15
|
|
@@ -7,13 +7,11 @@ class CreateWorkItemsTable < ActiveRecord::Migration[5.0]
|
|
7
7
|
create_table :work_items do |t|
|
8
8
|
t.string :type
|
9
9
|
if ActiveRecord::Base.connection.instance_values["config"][:adapter] == "postgresql"
|
10
|
-
t.jsonb :properties
|
11
|
-
t.jsonb :options
|
12
|
-
t.jsonb :status_log
|
10
|
+
t.jsonb :properties, default: {}
|
11
|
+
t.jsonb :options, default: {}
|
13
12
|
else
|
14
|
-
t.json :properties
|
15
|
-
t.json :options
|
16
|
-
t.json :status_log
|
13
|
+
t.json :properties, default: {}
|
14
|
+
t.json :options, default: {}
|
17
15
|
end
|
18
16
|
t.references :parent, foreign_key: {to_table: :work_items, on_delete: :cascade}
|
19
17
|
t.references :job, foreign_key: {to_table: :jobs, on_delete: :cascade}
|
@@ -21,9 +19,5 @@ class CreateWorkItemsTable < ActiveRecord::Migration[5.0]
|
|
21
19
|
t.timestamps
|
22
20
|
end
|
23
21
|
|
24
|
-
if ActiveRecord::Base.connection.instance_values["config"][:adapter] == "postgresql"
|
25
|
-
add_index :work_items, :status_log, using: :gin
|
26
|
-
end
|
27
|
-
|
28
22
|
end
|
29
23
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'libis/workflow/activerecord'
|
2
|
+
|
3
|
+
class CreateStatusesTable < ActiveRecord::Migration[5.0]
|
4
|
+
|
5
|
+
# noinspection RubyResolve
|
6
|
+
def change
|
7
|
+
|
8
|
+
create_table :statuses do |t|
|
9
|
+
t.string :task
|
10
|
+
t.string :status, limit: 12
|
11
|
+
t.integer :progress
|
12
|
+
t.integer :max
|
13
|
+
|
14
|
+
t.references :work_item, foreign_key: {to_table: :work_items, on_delete: :cascade}
|
15
|
+
|
16
|
+
t.timestamps
|
17
|
+
end
|
18
|
+
|
19
|
+
add_index :statuses, [:task, :id]
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/db/schema.rb
CHANGED
@@ -51,13 +51,11 @@ ActiveRecord::Schema.define do
|
|
51
51
|
create_table :work_items, force: :cascade do |t|
|
52
52
|
t.string :type
|
53
53
|
if ActiveRecord::Base.connection.instance_values["config"][:adapter] == "postgresql"
|
54
|
-
t.jsonb :properties
|
55
|
-
t.jsonb :options
|
56
|
-
t.jsonb :status_log
|
54
|
+
t.jsonb :properties, default: {}
|
55
|
+
t.jsonb :options, default: {}
|
57
56
|
else
|
58
|
-
t.json :properties
|
59
|
-
t.json :options
|
60
|
-
t.json :status_log
|
57
|
+
t.json :properties, default: {}
|
58
|
+
t.json :options, default: {}
|
61
59
|
end
|
62
60
|
t.references :parent, foreign_key: {to_table: :work_items, on_delete: :cascade}
|
63
61
|
t.references :job, foreign_key: {to_table: :jobs, on_delete: :cascade}
|
@@ -65,8 +63,18 @@ ActiveRecord::Schema.define do
|
|
65
63
|
t.timestamps
|
66
64
|
end
|
67
65
|
|
68
|
-
|
69
|
-
|
66
|
+
create_table :statuses, force: :cascade do |t|
|
67
|
+
t.string :task
|
68
|
+
t.string :status, limit: 12
|
69
|
+
t.integer :progress
|
70
|
+
t.integer :max
|
71
|
+
t.datetime :created
|
72
|
+
t.datetime :updated
|
73
|
+
|
74
|
+
t.references :work_item, foreign_key: {to_table: :work_items, on_delete: :cascade}
|
75
|
+
|
70
76
|
end
|
71
77
|
|
78
|
+
add_index :statuses, [:task, :id]
|
79
|
+
|
72
80
|
end
|
@@ -14,6 +14,7 @@ module Libis
|
|
14
14
|
autoload :Job, 'libis/workflow/activerecord/job'
|
15
15
|
autoload :Worker, 'libis/workflow/activerecord/worker'
|
16
16
|
autoload :Workflow, 'libis/workflow/activerecord/workflow'
|
17
|
+
autoload :Status, 'libis/workflow/activerecord/status'
|
17
18
|
|
18
19
|
def self.configure
|
19
20
|
yield ::Libis::Workflow::ActiveRecord::Config.instance
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Libis
|
2
|
+
module Workflow
|
3
|
+
module ActiveRecord
|
4
|
+
module Helpers
|
5
|
+
|
6
|
+
class SymbolSerializer
|
7
|
+
|
8
|
+
def self.dump(value)
|
9
|
+
value&.to_s rescue nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.load(value)
|
13
|
+
value&.to_sym rescue nil
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'libis-workflow-activerecord'
|
2
|
+
|
3
|
+
require_relative 'helpers/symbol_serializer'
|
4
|
+
|
5
|
+
module Libis
|
6
|
+
module Workflow
|
7
|
+
module ActiveRecord
|
8
|
+
|
9
|
+
class Status < ::ActiveRecord::Base
|
10
|
+
include Libis::Workflow::ActiveRecord::Base
|
11
|
+
|
12
|
+
serialize :status, Libis::Workflow::ActiveRecord::Helpers::SymbolSerializer
|
13
|
+
|
14
|
+
# noinspection RailsParamDefResolve
|
15
|
+
belongs_to :work_item, class_name: Libis::Workflow::ActiveRecord::WorkItem.to_s,
|
16
|
+
inverse_of: :status_log,
|
17
|
+
autosave: true
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Libis
|
2
2
|
module Workflow
|
3
3
|
module ActiveRecord
|
4
|
-
VERSION = '0.9.
|
4
|
+
VERSION = '0.9.2' unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
|
5
5
|
end
|
6
6
|
end
|
7
7
|
end
|
@@ -20,7 +20,14 @@ module Libis
|
|
20
20
|
# noinspection RubyArgCount
|
21
21
|
serialize :properties, Libis::Workflow::ActiveRecord::Helpers::HashSerializer
|
22
22
|
# noinspection RubyArgCount
|
23
|
-
serialize :status_log, Libis::Workflow::ActiveRecord::Helpers::StatusSerializer
|
23
|
+
# serialize :status_log, Libis::Workflow::ActiveRecord::Helpers::StatusSerializer
|
24
|
+
#
|
25
|
+
# noinspection RailsParamDefResolve
|
26
|
+
has_many :status_log,
|
27
|
+
-> {order('id')},
|
28
|
+
class_name: Libis::Workflow::ActiveRecord::Status.to_s,
|
29
|
+
foreign_key: :work_item_id,
|
30
|
+
autosave: true
|
24
31
|
|
25
32
|
# noinspection RailsParamDefResolve
|
26
33
|
has_many :items,
|
@@ -45,7 +52,6 @@ module Libis
|
|
45
52
|
self.properties.each {|k, v| new_item.properties[k.to_sym] = v.dup}
|
46
53
|
new_item.options = {}.with_indifferent_access
|
47
54
|
self.options.each {|k, v| new_item.options[k.to_sym] = v.dup}
|
48
|
-
new_item.status_log = []
|
49
55
|
yield new_item if block_given?
|
50
56
|
new_item
|
51
57
|
end
|
@@ -68,19 +74,34 @@ module Libis
|
|
68
74
|
end
|
69
75
|
|
70
76
|
def get_items
|
71
|
-
self.items
|
77
|
+
self.items.order(:id)
|
72
78
|
end
|
73
79
|
|
74
80
|
def get_item_list
|
75
|
-
|
81
|
+
get_items.to_a
|
76
82
|
end
|
77
83
|
|
78
84
|
protected
|
79
85
|
|
86
|
+
def save_log_entry(log_entry)
|
87
|
+
log_entry.save!
|
88
|
+
self.reload
|
89
|
+
end
|
90
|
+
|
91
|
+
def status_entry(task = nil)
|
92
|
+
task = task.namepath if task.is_a?(Libis::Workflow::Task)
|
93
|
+
return self.status_log.order(id: :asc).last if task.blank?
|
94
|
+
self.status_log.where(task: task).order(id: :asc).last
|
95
|
+
rescue Exception
|
96
|
+
nil
|
97
|
+
end
|
98
|
+
|
80
99
|
def add_status_log(info)
|
81
|
-
|
82
|
-
self.status_log << info.with_indifferent_access
|
100
|
+
self.status_log.build(info)
|
83
101
|
self.status_log.last
|
102
|
+
# noinspection RubyResolve
|
103
|
+
# self.status_log << info.with_indifferent_access
|
104
|
+
# self.status_log.last
|
84
105
|
end
|
85
106
|
|
86
107
|
end
|
@@ -11,6 +11,8 @@ module Libis
|
|
11
11
|
include ::Libis::Workflow::Base::Workflow
|
12
12
|
include ::Libis::Workflow::ActiveRecord::Base
|
13
13
|
|
14
|
+
serialize :input, Libis::Workflow::ActiveRecord::Helpers::HashSerializer
|
15
|
+
|
14
16
|
# noinspection RailsParamDefResolve
|
15
17
|
has_many :jobs,
|
16
18
|
-> {order('id')},
|
@@ -6,6 +6,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
6
6
|
require 'libis/workflow/activerecord/version'
|
7
7
|
require 'date'
|
8
8
|
|
9
|
+
# noinspection RubyResolve
|
9
10
|
Gem::Specification.new do |spec|
|
10
11
|
spec.name = 'libis-workflow-activerecord'
|
11
12
|
spec.version = ::Libis::Workflow::ActiveRecord::VERSION
|
@@ -19,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
19
20
|
spec.homepage = 'https://github.com/libis/workflow-activerecord'
|
20
21
|
spec.license = 'MIT'
|
21
22
|
|
23
|
+
# noinspection RubyResolve
|
22
24
|
spec.platform = Gem::Platform::JAVA if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
23
25
|
|
24
26
|
spec.files = `git ls-files -z`.split("\0")
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'coveralls'
|
2
2
|
Coveralls.wear!
|
3
3
|
|
4
|
+
# noinspection RubyResolve
|
4
5
|
require 'bundler/setup'
|
6
|
+
# noinspection RubyResolve
|
5
7
|
Bundler.setup
|
6
8
|
|
7
9
|
require 'rspec'
|
@@ -13,14 +15,17 @@ require 'stringio'
|
|
13
15
|
RSpec.configure do |cfg|
|
14
16
|
|
15
17
|
cfg.before :suite do
|
16
|
-
|
17
|
-
|
18
|
-
cfg.logger.appenders =
|
18
|
+
::Libis::Workflow::ActiveRecord.configure do |config|
|
19
|
+
config.logger.appenders =
|
19
20
|
::Logging::Appenders.string_io('StringIO', layout: ::Libis::Tools::Config.get_log_formatter)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
# noinspection RubyResolve
|
22
|
+
config.itemdir = File.join(File.dirname(__FILE__), 'items')
|
23
|
+
# noinspection RubyResolve
|
24
|
+
config.taskdir = File.join(File.dirname(__FILE__), 'tasks')
|
25
|
+
# noinspection RubyResolve
|
26
|
+
config.workdir = File.join(File.dirname(__FILE__), 'work')
|
27
|
+
# noinspection RubyResolve
|
28
|
+
config.database_connect 'db/config.yml', :test
|
24
29
|
end
|
25
30
|
DatabaseCleaner.clean_with :truncation
|
26
31
|
end
|
data/spec/workflow_spec.rb
CHANGED
@@ -24,6 +24,7 @@ describe 'TestWorkflow' do
|
|
24
24
|
|
25
25
|
let(:workflow) {
|
26
26
|
wf = TestWorkflow.find_or_initialize_by(name: 'TestWorkflow')
|
27
|
+
# noinspection RubyStringKeysInHashInspection
|
27
28
|
wf.configure(
|
28
29
|
'name' => 'TestWorkflow',
|
29
30
|
'description' => 'Workflow for testing',
|
@@ -47,6 +48,7 @@ describe 'TestWorkflow' do
|
|
47
48
|
wf
|
48
49
|
}
|
49
50
|
let(:job) {
|
51
|
+
# noinspection RubyStringKeysInHashInspection
|
50
52
|
job = TestJob.from_hash(
|
51
53
|
'name' => 'TestJob',
|
52
54
|
'description' => 'Job for testing',
|
@@ -73,7 +75,9 @@ describe 'TestWorkflow' do
|
|
73
75
|
job
|
74
76
|
}
|
75
77
|
|
76
|
-
let(:run) {
|
78
|
+
let(:run) {
|
79
|
+
job.execute
|
80
|
+
}
|
77
81
|
|
78
82
|
it 'should contain three tasks' do
|
79
83
|
|
data/spec/workitem_spec.rb
CHANGED
@@ -164,6 +164,7 @@ describe 'TestWorkItem' do
|
|
164
164
|
|
165
165
|
it 'updated' do
|
166
166
|
item.set_status('abc', :DONE)
|
167
|
+
item.reload
|
167
168
|
expect(item.status_log.size).to be 1
|
168
169
|
status_entry = item.status_log[0]
|
169
170
|
expect(status_entry[:task]).to eql 'abc'
|
@@ -184,6 +185,7 @@ describe 'TestWorkItem' do
|
|
184
185
|
|
185
186
|
it 'updated' do
|
186
187
|
item.status_progress('def', 3, 10)
|
188
|
+
item.reload
|
187
189
|
expect(item.status_log.size).to be 2
|
188
190
|
status_entry = item.status_log[1]
|
189
191
|
expect(status_entry[:task]).to eql 'def'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libis-workflow-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kris Dekeyser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: libis-workflow
|
@@ -166,6 +166,7 @@ files:
|
|
166
166
|
- db/migrate/001_create_workflow_table.rb
|
167
167
|
- db/migrate/002_create_jobs_table.rb
|
168
168
|
- db/migrate/003_create_work_items_table.rb
|
169
|
+
- db/migrate/004_create_statuses_table.rb
|
169
170
|
- db/schema.rb
|
170
171
|
- db/setup_db.rb
|
171
172
|
- db/travis.config.yml
|
@@ -176,8 +177,10 @@ files:
|
|
176
177
|
- lib/libis/workflow/activerecord/helpers/hash_serializer.rb
|
177
178
|
- lib/libis/workflow/activerecord/helpers/property_helper.rb
|
178
179
|
- lib/libis/workflow/activerecord/helpers/status_serializer.rb
|
180
|
+
- lib/libis/workflow/activerecord/helpers/symbol_serializer.rb
|
179
181
|
- lib/libis/workflow/activerecord/job.rb
|
180
182
|
- lib/libis/workflow/activerecord/run.rb
|
183
|
+
- lib/libis/workflow/activerecord/status.rb
|
181
184
|
- lib/libis/workflow/activerecord/version.rb
|
182
185
|
- lib/libis/workflow/activerecord/work_item.rb
|
183
186
|
- lib/libis/workflow/activerecord/worker.rb
|