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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3b864ebd79697b212e8e398b7c98080e22238ff38efa0d9e16f8ce2862e9904
4
- data.tar.gz: 89b6d5b72c99d3fa5bebcd63e03df3f29cafb95ecf76b179bac8649f9fb1ffad
3
+ metadata.gz: 379a7d33367283bc65ca129d9824af1e486e335e308481b702451f4c0dd2dec5
4
+ data.tar.gz: cf40df8e08387af400220bb24ac5f107540e5a00a3cf650a6f538c7260e8d6ef
5
5
  SHA512:
6
- metadata.gz: adffbcd7031d6d01291ee8a00e64f46b084f8a12e7b834bf232f42200d87b805be56540251fefb2c2d150d40260094776065dbee422b153b5bfeaf6f6ce4a197
7
- data.tar.gz: ff0e83c3a87d4197814486bb34367215d91f8807966ed6ca5fc0273329f6fe3da33709bc7297ae5cff9330ec9bc017a10df7d051c017fb80f0ce6d3834e78a85
6
+ metadata.gz: e31730b7390994d48673e1cbf358f62d4b2d05df8b7cf18c4d020cf25f94ba8f16c2a9ee41dea80db338457dfa8e63eb5d70237ae3694ca067c2f6d54f553380
7
+ data.tar.gz: a257bdf9e2bbe84a97e3114880307f2f38bb63217484443771cec173343cbd9465d57aedd76d29a3dc83c41df0e6796aa67b70b4b5c84b80f3dc0ccf73434546
data/Gemfile CHANGED
@@ -1,3 +1,4 @@
1
+ # noinspection RubyArgCount
1
2
  source 'https://rubygems.org'
2
3
 
3
4
  gemspec name: 'libis-workflow-activerecord', development_group: :test
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
- if ActiveRecord::Base.connection.instance_values["config"][:adapter] == "postgresql"
69
- add_index :work_items, :status_log, using: :gin
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
@@ -25,6 +25,8 @@ module Libis
25
25
 
26
26
  Config[:log_dir] = '.'
27
27
 
28
+ Config[:db_dir] = File.join(File.dirname(__FILE__),'..', '..', '..', '..', 'db')
29
+
28
30
  end
29
31
  end
30
32
  end
@@ -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.1' unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
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
- self.items.to_a
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
- # noinspection RubyResolve
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
- # noinspection RubyResolve
17
- ::Libis::Workflow::ActiveRecord.configure do |cfg|
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
- cfg.itemdir = File.join(File.dirname(__FILE__), 'items')
21
- cfg.taskdir = File.join(File.dirname(__FILE__), 'tasks')
22
- cfg.workdir = File.join(File.dirname(__FILE__), 'work')
23
- cfg.database_connect 'db/config.yml', :test
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
@@ -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) { job.execute }
78
+ let(:run) {
79
+ job.execute
80
+ }
77
81
 
78
82
  it 'should contain three tasks' do
79
83
 
@@ -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.1
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-07 00:00:00.000000000 Z
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