libis-workflow-activerecord 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +57 -0
- data/.travis.yml +50 -0
- data/Gemfile +3 -0
- data/README.md +13 -0
- data/Rakefile +85 -0
- data/db/config.yml +71 -0
- data/db/migrate/001_create_work_items_table.rb +18 -0
- data/db/migrate/002_create_jobs_table.rb +27 -0
- data/db/schema.rb +72 -0
- data/db/setup_db.rb +14 -0
- data/db/travis.config.yml +4 -0
- data/lib/libis-workflow-activerecord.rb +1 -0
- data/lib/libis/workflow/activerecord.rb +25 -0
- data/lib/libis/workflow/activerecord/base.rb +79 -0
- data/lib/libis/workflow/activerecord/config.rb +30 -0
- data/lib/libis/workflow/activerecord/helpers/hash_serializer.rb +32 -0
- data/lib/libis/workflow/activerecord/helpers/property_helper.rb +40 -0
- data/lib/libis/workflow/activerecord/helpers/status_serializer.rb +30 -0
- data/lib/libis/workflow/activerecord/job.rb +73 -0
- data/lib/libis/workflow/activerecord/run.rb +99 -0
- data/lib/libis/workflow/activerecord/version.rb +7 -0
- data/lib/libis/workflow/activerecord/work_item.rb +90 -0
- data/lib/libis/workflow/activerecord/worker.rb +20 -0
- data/lib/libis/workflow/activerecord/workflow.rb +40 -0
- data/libis-workflow-activerecord.gemspec +42 -0
- data/spec/db_env.sh +5 -0
- data/spec/db_start.sh +5 -0
- data/spec/items.rb +3 -0
- data/spec/items/test_dir_item.rb +18 -0
- data/spec/items/test_file_item.rb +29 -0
- data/spec/items/test_item.rb +6 -0
- data/spec/items/test_run.rb +8 -0
- data/spec/job_spec.rb +10 -0
- data/spec/run_spec.rb +4 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/tasks/camelize_name.rb +13 -0
- data/spec/tasks/checksum_tester.rb +34 -0
- data/spec/tasks/collect_files.rb +52 -0
- data/spec/test_job.rb +6 -0
- data/spec/test_workflow.rb +6 -0
- data/spec/test_workitem.rb +7 -0
- data/spec/workflow_spec.rb +208 -0
- data/spec/workitem_spec.rb +366 -0
- metadata +245 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5e5ca19333207c2454878483bec80747d8af6717
|
4
|
+
data.tar.gz: 4006386a833854575803812cb7f379f43baafb21
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f90d6c9a59ccbaec455a9ece2bf6759d60ba2bddafbecf3f37470117eb2b2ec7738c2f942c80fdf81825a57abd641343ac4acb75817a7d0861f5de26495ba69e
|
7
|
+
data.tar.gz: 4fc925d21262f45aa265658ac39cbc558401dd40057bdfc7be801429a8b5522309ec299d978ed9f624360b6c3483b01352e340570159a692fc552614760a4fba
|
data/.gitignore
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Created by .ignore support plugin (hsz.mobi)
|
2
|
+
### Ruby template
|
3
|
+
*.gem
|
4
|
+
*.rbc
|
5
|
+
/.config
|
6
|
+
/coverage/
|
7
|
+
/InstalledFiles
|
8
|
+
/pkg/
|
9
|
+
/spec/reports/
|
10
|
+
/spec/examples.txt
|
11
|
+
/test/tmp/
|
12
|
+
/test/version_tmp/
|
13
|
+
/tmp/
|
14
|
+
|
15
|
+
# Used by dotenv library to load environment variables.
|
16
|
+
# .env
|
17
|
+
|
18
|
+
## Specific to RubyMotion:
|
19
|
+
.dat*
|
20
|
+
.repl_history
|
21
|
+
build/
|
22
|
+
*.bridgesupport
|
23
|
+
build-iPhoneOS/
|
24
|
+
build-iPhoneSimulator/
|
25
|
+
|
26
|
+
## Specific to RubyMotion (use of CocoaPods):
|
27
|
+
#
|
28
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
29
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
30
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
31
|
+
#
|
32
|
+
# vendor/Pods/
|
33
|
+
|
34
|
+
## Documentation cache and generated files:
|
35
|
+
/.yardoc/
|
36
|
+
/_yardoc/
|
37
|
+
/doc/
|
38
|
+
/rdoc/
|
39
|
+
|
40
|
+
## Environment normalization:
|
41
|
+
/.bundle/
|
42
|
+
/vendor/bundle
|
43
|
+
/lib/bundler/man/
|
44
|
+
|
45
|
+
# for a library or gem, you might want to ignore these files since the code is
|
46
|
+
# intended to run in multiple environments; otherwise, check them in:
|
47
|
+
Gemfile.lock
|
48
|
+
.ruby-version
|
49
|
+
.ruby-gemset
|
50
|
+
|
51
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
52
|
+
.rvmrc
|
53
|
+
*.db
|
54
|
+
|
55
|
+
# Rubymine project files
|
56
|
+
*.iml
|
57
|
+
.idea
|
data/.travis.yml
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
bundler_args: --without development
|
4
|
+
cache: bundler
|
5
|
+
|
6
|
+
rvm:
|
7
|
+
- 2.3.0
|
8
|
+
- 2.4.1
|
9
|
+
- 2.5.0
|
10
|
+
- ruby-head
|
11
|
+
- jruby-9.1.9.0
|
12
|
+
- jruby-head
|
13
|
+
jdk:
|
14
|
+
- openjdk8
|
15
|
+
- oraclejdk8
|
16
|
+
- oraclejdk9
|
17
|
+
matrix:
|
18
|
+
exclude:
|
19
|
+
- rvm: 2.3.0
|
20
|
+
jdk: oraclejdk8
|
21
|
+
- rvm: 2.3.0
|
22
|
+
jdk: oraclejdk9
|
23
|
+
- rvm: 2.4.1
|
24
|
+
jdk: oraclejdk8
|
25
|
+
- rvm: 2.4.1
|
26
|
+
jdk: oraclejdk9
|
27
|
+
- rvm: 2.5.0
|
28
|
+
jdk: oraclejdk8
|
29
|
+
- rvm: 2.5.0
|
30
|
+
jdk: oraclejdk9
|
31
|
+
- rvm: ruby-head
|
32
|
+
jdk: oraclejdk8
|
33
|
+
- rvm: ruby-head
|
34
|
+
jdk: oraclejdk9
|
35
|
+
allow_failures:
|
36
|
+
- rvm: ruby-head
|
37
|
+
- rvm: jruby-head
|
38
|
+
branches:
|
39
|
+
only:
|
40
|
+
- master
|
41
|
+
env:
|
42
|
+
global:
|
43
|
+
- JRUBY_OPTS="-Xcli.debug=true --debug"
|
44
|
+
addons:
|
45
|
+
postgresql: "9.6"
|
46
|
+
services:
|
47
|
+
- postgresql
|
48
|
+
before_script:
|
49
|
+
- psql -c 'create database upload;' -U postgres
|
50
|
+
- cp db/travis.config.yml db/config.yml
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/libis-workflow-activerecord.svg)](http://badge.fury.io/rb/libis-workflow-activerecord)
|
2
|
+
[![Build Status](https://travis-ci.org/Kris-LIBIS/workflow-activerecord.svg?branch=master)](https://travis-ci.org/Kris-LIBIS/workflow-activerecord)
|
3
|
+
[![Coverage Status](https://coveralls.io/repos/Kris-LIBIS/workflow-activerecord/badge.png)](https://coveralls.io/r/Kris-LIBIS/workflow-activerecord)
|
4
|
+
[![Dependency Status](https://gemnasium.com/Kris-LIBIS/workflow-activerecord.svg)](https://gemnasium.com/Kris-LIBIS/workflow-activerecord)
|
5
|
+
|
6
|
+
workflow-activerecord
|
7
|
+
=====================
|
8
|
+
|
9
|
+
ActiveRecord persistence for the workflow framework.
|
10
|
+
|
11
|
+
Note: This gem only supports Postgres and MySql as it needs support for json data type in the DB.
|
12
|
+
When - and if - the sqlite3 adapter adds support for the sqlite JSON1 extension, this gem
|
13
|
+
is expected to support sqlite as well.
|
data/Rakefile
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new('spec')
|
5
|
+
|
6
|
+
desc 'run tests'
|
7
|
+
task :default => :spec
|
8
|
+
|
9
|
+
require 'yaml'
|
10
|
+
require 'logger'
|
11
|
+
require 'active_record'
|
12
|
+
|
13
|
+
namespace :db do
|
14
|
+
def create_database(config)
|
15
|
+
options = {:charset => 'utf8', :collation => 'utf8_unicode_ci'}
|
16
|
+
|
17
|
+
create_db = lambda do |cfg|
|
18
|
+
ActiveRecord::Base.establish_connection cfg.merge('database' => nil)
|
19
|
+
ActiveRecord::Base.connection.create_database cfg['database'], options
|
20
|
+
ActiveRecord::Base.establish_connection cfg
|
21
|
+
end
|
22
|
+
|
23
|
+
begin
|
24
|
+
create_db.call config
|
25
|
+
# rescue Mysql::Error => sqlerr
|
26
|
+
# if sqlerr.errno == 1405
|
27
|
+
# print "#{sqlerr.error}. \nPlease provide the root password for your mysql installation\n>"
|
28
|
+
# root_password = $stdin.gets.strip
|
29
|
+
#
|
30
|
+
# grant_statement = <<-SQL
|
31
|
+
# GRANT ALL PRIVILEGES ON #{config['database']}.*
|
32
|
+
# TO '#{config['username']}'@'localhost'
|
33
|
+
# IDENTIFIED BY '#{config['password']}' WITH GRANT OPTION;
|
34
|
+
# SQL
|
35
|
+
#
|
36
|
+
# create_db.call config.merge('database' => nil, 'username' => 'root', 'password' => root_password)
|
37
|
+
# else
|
38
|
+
# $stderr.puts sqlerr.error
|
39
|
+
# $stderr.puts "Couldn't create database for #{config.inspect}, charset: utf8, collation: utf8_unicode_ci"
|
40
|
+
# $stderr.puts "(if you set the charset manually, make sure you have a matching collation)" if config['charset']
|
41
|
+
# end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
task :environment do
|
46
|
+
DATABASE_ENV = ENV['DATABASE_ENV'] || 'development'
|
47
|
+
MIGRATIONS_DIR = ENV['MIGRATIONS_DIR'] || 'db/migrate'
|
48
|
+
end
|
49
|
+
|
50
|
+
task :configuration => :environment do
|
51
|
+
@config = YAML.load_file('db/config.yml')[DATABASE_ENV]
|
52
|
+
end
|
53
|
+
|
54
|
+
task :configure_connection => :configuration do
|
55
|
+
ActiveRecord::Base.establish_connection @config
|
56
|
+
ActiveRecord::Base.logger = Logger.new STDOUT if @config['logger']
|
57
|
+
end
|
58
|
+
|
59
|
+
desc 'Create the database from db/config.yml for the current DATABASE_ENV'
|
60
|
+
task :create => :configure_connection do
|
61
|
+
create_database @config
|
62
|
+
end
|
63
|
+
|
64
|
+
desc 'Drops the database for the current DATABASE_ENV'
|
65
|
+
task :drop => :configure_connection do
|
66
|
+
ActiveRecord::Base.connection.drop_database @config['database']
|
67
|
+
end
|
68
|
+
|
69
|
+
desc 'Migrate the database (options: VERSION=x, VERBOSE=false).'
|
70
|
+
task :migrate => :configure_connection do
|
71
|
+
ActiveRecord::Migration.verbose = true
|
72
|
+
ActiveRecord::Migrator.migrate MIGRATIONS_DIR, ENV['VERSION'] ? ENV['VERSION'].to_i : nil
|
73
|
+
end
|
74
|
+
|
75
|
+
desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).'
|
76
|
+
task :rollback => :configure_connection do
|
77
|
+
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
78
|
+
ActiveRecord::Migrator.rollback MIGRATIONS_DIR, step
|
79
|
+
end
|
80
|
+
|
81
|
+
desc 'Retrieves the current schema version number'
|
82
|
+
task :version => :configure_connection do
|
83
|
+
puts "Current version: #{ActiveRecord::Migrator.current_version}"
|
84
|
+
end
|
85
|
+
end
|
data/db/config.yml
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
default: &default
|
2
|
+
adapter: postgresql
|
3
|
+
encoding: unicode
|
4
|
+
database: upload
|
5
|
+
host: localhost
|
6
|
+
port: 5432
|
7
|
+
username: upload
|
8
|
+
password: upload
|
9
|
+
# For details on connection pooling, see Rails configuration guide
|
10
|
+
# http://guides.rubyonrails.org/configuring.html#database-pooling
|
11
|
+
pool: 20
|
12
|
+
|
13
|
+
development:
|
14
|
+
<<: *default
|
15
|
+
|
16
|
+
# The specified database role being used to connect to postgres.
|
17
|
+
# To create additional roles in postgres see `$ createuser --help`.
|
18
|
+
# When left blank, postgres will use the default role. This is
|
19
|
+
# the same name as the operating system user that initialized the database.
|
20
|
+
#username: Uploader
|
21
|
+
|
22
|
+
# The password associated with the postgres role (username).
|
23
|
+
#password:
|
24
|
+
|
25
|
+
# Connect on a TCP socket. Omitted by default since the client uses a
|
26
|
+
# domain socket that doesn't need configuration. Windows does not have
|
27
|
+
# domain sockets, so uncomment these lines.
|
28
|
+
#host: localhost
|
29
|
+
|
30
|
+
# The TCP port the server listens on. Defaults to 5432.
|
31
|
+
# If your server runs on a different port number, change accordingly.
|
32
|
+
#port: 5432
|
33
|
+
|
34
|
+
# Schema search path. The server defaults to $user,public
|
35
|
+
#schema_search_path: myapp,sharedapp,public
|
36
|
+
|
37
|
+
# Minimum log levels, in increasing order:
|
38
|
+
# debug5, debug4, debug3, debug2, debug1,
|
39
|
+
# log, notice, warning, error, fatal, and panic
|
40
|
+
# Defaults to warning.
|
41
|
+
min_messages: debug5
|
42
|
+
|
43
|
+
# Warning: The database defined as "test" will be erased and
|
44
|
+
# re-generated from your development database when you run "rake".
|
45
|
+
# Do not set this db to the same as development or production.
|
46
|
+
test:
|
47
|
+
<<: *default
|
48
|
+
min_messages: warning
|
49
|
+
|
50
|
+
# As with config/secrets.yml, you never want to store sensitive information,
|
51
|
+
# like your database password, in your source code. If your source code is
|
52
|
+
# ever seen by anyone, they now have access to your database.
|
53
|
+
#
|
54
|
+
# Instead, provide the password as a unix environment variable when you boot
|
55
|
+
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
|
56
|
+
# for a full rundown on how to provide these environment variables in a
|
57
|
+
# production deployment.
|
58
|
+
#
|
59
|
+
# On Heroku and other platform providers, you may have a full connection URL
|
60
|
+
# available as an environment variable. For example:
|
61
|
+
#
|
62
|
+
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
|
63
|
+
#
|
64
|
+
# You can use this database configuration with:
|
65
|
+
#
|
66
|
+
# production:
|
67
|
+
# url: <%= ENV['DATABASE_URL'] %>
|
68
|
+
#
|
69
|
+
production:
|
70
|
+
<<: *default
|
71
|
+
min_messages: warning
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'libis/workflow/activerecord'
|
2
|
+
|
3
|
+
class CreateWorkflowItemsTable < ActiveRecord::Migration[5.0]
|
4
|
+
|
5
|
+
def change
|
6
|
+
create_table :work_items do |t|
|
7
|
+
t.string :type
|
8
|
+
t.jsonb :properties
|
9
|
+
t.jsonb :options
|
10
|
+
t.jsonb :status_log
|
11
|
+
t.references :parent, foreign_key: {to_table: :work_items, on_delete: :cascade}
|
12
|
+
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
add_index :work_items, :status_log, using: :gin
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'libis/workflow/activerecord'
|
2
|
+
|
3
|
+
class CreateWorkflowItemsTable < ActiveRecord::Migration[5.0]
|
4
|
+
|
5
|
+
def change
|
6
|
+
create_table :jobs do |t|
|
7
|
+
t.string :type
|
8
|
+
t.string :name
|
9
|
+
t.string :description
|
10
|
+
t.jsonb :input
|
11
|
+
t.string :run_object
|
12
|
+
t.boolean :log_to_file, default: true
|
13
|
+
t.boolean :log_each_run, default: true
|
14
|
+
t.string :log_level, default: 'INFO'
|
15
|
+
t.string :log_age, default: 'daily'
|
16
|
+
# noinspection RubyResolve
|
17
|
+
t.integer :log_keep, default: 5
|
18
|
+
|
19
|
+
t.timestamps
|
20
|
+
|
21
|
+
t.integer :run_id
|
22
|
+
t.integer :workflow_id
|
23
|
+
end
|
24
|
+
|
25
|
+
add_index :jobs, :workflow_id
|
26
|
+
end
|
27
|
+
end
|
data/db/schema.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
self.verbose = true
|
3
|
+
|
4
|
+
enable_extension 'plpgsql'
|
5
|
+
|
6
|
+
# enable_extension 'pgcrypto'
|
7
|
+
|
8
|
+
create_table :workflows, force: :cascade do |t|
|
9
|
+
t.string :type
|
10
|
+
t.string :name
|
11
|
+
t.text :description
|
12
|
+
if ActiveRecord::Base.connection.instance_values["config"][:adapter] == "postgresql"
|
13
|
+
t.jsonb :config, default: {}
|
14
|
+
else
|
15
|
+
t.json :config, default: {}
|
16
|
+
end
|
17
|
+
|
18
|
+
t.timestamps
|
19
|
+
end
|
20
|
+
|
21
|
+
if ActiveRecord::Base.connection.instance_values["config"][:adapter] == "postgresql"
|
22
|
+
add_index :workflows, :config, using: :gin
|
23
|
+
end
|
24
|
+
|
25
|
+
create_table :jobs, force: :cascade do |t|
|
26
|
+
t.string :type
|
27
|
+
t.string :name
|
28
|
+
t.text :description
|
29
|
+
if ActiveRecord::Base.connection.instance_values["config"][:adapter] == "postgresql"
|
30
|
+
t.jsonb :input, default: {}
|
31
|
+
else
|
32
|
+
t.json :input, default: {}
|
33
|
+
end
|
34
|
+
t.string :run_object
|
35
|
+
t.boolean :log_to_file, default: true
|
36
|
+
t.boolean :log_each_run, default: true
|
37
|
+
t.string :log_level, default: 'INFO'
|
38
|
+
t.string :log_age, default: 'daily'
|
39
|
+
# noinspection RubyResolve
|
40
|
+
t.integer :log_keep, default: 5
|
41
|
+
|
42
|
+
t.timestamps
|
43
|
+
|
44
|
+
t.references :workflow, foreign_key: {to_table: :workflows, on_delete: :cascade}
|
45
|
+
t.integer :workflow_id
|
46
|
+
end
|
47
|
+
|
48
|
+
if ActiveRecord::Base.connection.instance_values["config"][:adapter] == "postgresql"
|
49
|
+
add_index :jobs, :input, using: :gin
|
50
|
+
end
|
51
|
+
|
52
|
+
create_table :work_items, force: :cascade do |t|
|
53
|
+
t.string :type
|
54
|
+
if ActiveRecord::Base.connection.instance_values["config"][:adapter] == "postgresql"
|
55
|
+
t.jsonb :properties
|
56
|
+
t.jsonb :options
|
57
|
+
t.jsonb :status_log
|
58
|
+
else
|
59
|
+
t.json :properties
|
60
|
+
t.json :options
|
61
|
+
t.json :status_log
|
62
|
+
end
|
63
|
+
t.references :parent, foreign_key: {to_table: :work_items, on_delete: :cascade}
|
64
|
+
t.references :job, foreign_key: {to_table: :jobs, on_delete: :cascade}
|
65
|
+
t.timestamps
|
66
|
+
end
|
67
|
+
|
68
|
+
if ActiveRecord::Base.connection.instance_values["config"][:adapter] == "postgresql"
|
69
|
+
add_index :work_items, :status_log, using: :gin
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
data/db/setup_db.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
root_dir = File.join(File.dirname(__FILE__), '..')
|
2
|
+
Dir.chdir root_dir
|
3
|
+
$:.unshift File.join(root_dir, 'lib')
|
4
|
+
|
5
|
+
require 'libis-workflow-activerecord'
|
6
|
+
|
7
|
+
::Libis::Workflow::ActiveRecord.configure do |cfg|
|
8
|
+
# noinspection RubyResolve
|
9
|
+
cfg.database_connect 'db/config.yml', :test
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'database_cleaner'
|
13
|
+
|
14
|
+
load 'db/schema.rb'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'libis/workflow/activerecord'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'libis-workflow'
|
2
|
+
|
3
|
+
require_relative 'activerecord/version'
|
4
|
+
require 'active_record'
|
5
|
+
|
6
|
+
module Libis
|
7
|
+
module Workflow
|
8
|
+
module ActiveRecord
|
9
|
+
|
10
|
+
autoload :Base, 'libis/workflow/activerecord/base'
|
11
|
+
autoload :Config, 'libis/workflow/activerecord/config'
|
12
|
+
autoload :WorkItem, 'libis/workflow/activerecord/work_item'
|
13
|
+
autoload :Run, 'libis/workflow/activerecord/run'
|
14
|
+
autoload :Job, 'libis/workflow/activerecord/job'
|
15
|
+
autoload :Worker, 'libis/workflow/activerecord/worker'
|
16
|
+
autoload :Workflow, 'libis/workflow/activerecord/workflow'
|
17
|
+
|
18
|
+
def self.configure
|
19
|
+
yield ::Libis::Workflow::ActiveRecord::Config.instance
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|