libis-workflow-mongoid 2.0.beta.13-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +38 -0
- data/.travis/create_users.js +31 -0
- data/.travis/db_prepare.sh +7 -0
- data/.travis.yml +45 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +8 -0
- data/Rakefile +7 -0
- data/lib/libis/workflow/mongoid/base.rb +58 -0
- data/lib/libis/workflow/mongoid/config.rb +27 -0
- data/lib/libis/workflow/mongoid/dynamic.rb +32 -0
- data/lib/libis/workflow/mongoid/job.rb +47 -0
- data/lib/libis/workflow/mongoid/log_entry.rb +28 -0
- data/lib/libis/workflow/mongoid/run.rb +72 -0
- data/lib/libis/workflow/mongoid/sequence.rb +79 -0
- data/lib/libis/workflow/mongoid/version.rb +9 -0
- data/lib/libis/workflow/mongoid/work_item.rb +39 -0
- data/lib/libis/workflow/mongoid/work_item_base.rb +107 -0
- data/lib/libis/workflow/mongoid/worker.rb +22 -0
- data/lib/libis/workflow/mongoid/workflow.rb +48 -0
- data/lib/libis/workflow/mongoid.rb +28 -0
- data/lib/libis-workflow-mongoid.rb +2 -0
- data/libis-workflow-mongoid.gemspec +39 -0
- data/mongoid.yml +127 -0
- data/spec/db_env.sh +5 -0
- data/spec/db_start.sh +5 -0
- data/spec/items/test_dir_item.rb +17 -0
- data/spec/items/test_file_item.rb +28 -0
- data/spec/items/test_item.rb +8 -0
- data/spec/items/test_run.rb +12 -0
- data/spec/items.rb +3 -0
- data/spec/spec_helper.rb +8 -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 +9 -0
- data/spec/test_workflow.rb +8 -0
- data/spec/workflow_spec.rb +201 -0
- metadata +193 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'libis/workflow/worker'
|
4
|
+
require 'sidekiq'
|
5
|
+
|
6
|
+
module Libis
|
7
|
+
module Workflow
|
8
|
+
module Mongoid
|
9
|
+
|
10
|
+
class Worker < Libis::Workflow::Worker
|
11
|
+
|
12
|
+
def get_job(job_config)
|
13
|
+
job_name = job_config.delete(:name)
|
14
|
+
job = ::Libis::Workflow::Mongoid::Job.find(name: job_name).first
|
15
|
+
raise RuntimeError.new "Workflow #{job_name} not found" unless job.is_a? ::Libis::Workflow::Mongoid::Job
|
16
|
+
job
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'libis/workflow/base/workflow'
|
4
|
+
require 'libis/workflow/mongoid/base'
|
5
|
+
require 'libis/tools/config_file'
|
6
|
+
require 'libis/tools/extend/hash'
|
7
|
+
|
8
|
+
module Libis
|
9
|
+
module Workflow
|
10
|
+
module Mongoid
|
11
|
+
|
12
|
+
module Workflow
|
13
|
+
|
14
|
+
def self.included(klass)
|
15
|
+
klass.class_eval do
|
16
|
+
include ::Libis::Workflow::Base::Workflow
|
17
|
+
include ::Libis::Workflow::Mongoid::Base
|
18
|
+
|
19
|
+
store_in collection: 'workflow_definitions'
|
20
|
+
|
21
|
+
field :name, type: String
|
22
|
+
field :description, type: String
|
23
|
+
field :config, type: Hash, default: -> { Hash.new }
|
24
|
+
|
25
|
+
index({name: 1}, {unique: 1})
|
26
|
+
|
27
|
+
def klass.job_class(job_klass)
|
28
|
+
has_many :jobs, inverse_of: :workflow, class_name: job_klass.to_s,
|
29
|
+
dependent: :destroy, autosave: true, order: :c_at.asc
|
30
|
+
end
|
31
|
+
|
32
|
+
def klass.load(file_or_hash)
|
33
|
+
config = Libis::Tools::ConfigFile.new
|
34
|
+
config << file_or_hash
|
35
|
+
return nil if config.empty?
|
36
|
+
workflow = self.new
|
37
|
+
workflow.configure(config.to_hash.key_strings_to_symbols(recursive: true))
|
38
|
+
workflow
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'libis-workflow'
|
4
|
+
|
5
|
+
require_relative 'mongoid/version'
|
6
|
+
|
7
|
+
module Libis
|
8
|
+
module Workflow
|
9
|
+
module Mongoid
|
10
|
+
|
11
|
+
autoload :Base, 'libis/workflow/mongoid/base'
|
12
|
+
autoload :Config, 'libis/workflow/mongoid/config'
|
13
|
+
autoload :LogEntry, 'libis/workflow/mongoid/log_entry'
|
14
|
+
autoload :Job, 'libis/workflow/mongoid/job'
|
15
|
+
autoload :Run, 'libis/workflow/mongoid/run'
|
16
|
+
autoload :WorkItem, 'libis/workflow/mongoid/work_item'
|
17
|
+
autoload :WorkItemBase, 'libis/workflow/mongoid/work_item_base'
|
18
|
+
autoload :Worker, 'libis/workflow/mongoid/worker'
|
19
|
+
autoload :Workflow, 'libis/workflow/mongoid/workflow'
|
20
|
+
|
21
|
+
def self.configure
|
22
|
+
yield ::Libis::Workflow::Mongoid::Config.instance
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'libis/workflow/mongoid/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'libis-workflow-mongoid'
|
10
|
+
spec.version = ::Libis::Workflow::Mongoid::VERSION
|
11
|
+
spec.date = Date.today.to_s
|
12
|
+
|
13
|
+
spec.summary = %q{Mongoid persistence for the LIBIS Workflow framework.}
|
14
|
+
spec.description = %q{Class implementations that use Mongoid storage for the LIBIS Workflow framework.}
|
15
|
+
|
16
|
+
spec.author = 'Kris Dekeyser'
|
17
|
+
spec.email = 'kris.dekeyser@libis.be'
|
18
|
+
spec.homepage = 'https://github.com/libis/workflow-mongoid'
|
19
|
+
spec.license = 'MIT'
|
20
|
+
|
21
|
+
spec.platform = Gem::Platform::JAVA if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\0")
|
24
|
+
spec.executables = spec.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
25
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
26
|
+
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
|
29
|
+
spec.add_runtime_dependency 'libis-workflow', '~> 2.0.beta'
|
30
|
+
|
31
|
+
spec.add_runtime_dependency 'mongoid', '~> 5.0'
|
32
|
+
spec.add_runtime_dependency 'sidekiq'
|
33
|
+
|
34
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
35
|
+
spec.add_development_dependency 'rake'
|
36
|
+
spec.add_development_dependency 'rspec'
|
37
|
+
spec.add_development_dependency 'coveralls'
|
38
|
+
|
39
|
+
end
|
data/mongoid.yml
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
# Mongoid Configuration for Travis CI
|
2
|
+
# ===================================
|
3
|
+
|
4
|
+
test:
|
5
|
+
# Configure available database clients. (required)
|
6
|
+
clients:
|
7
|
+
# Defines the default client. (required)
|
8
|
+
default:
|
9
|
+
# Defines the name of the default database that Mongoid can connect to.
|
10
|
+
# (required).
|
11
|
+
database: workflow_test
|
12
|
+
# Provides the hosts the default client can connect to. Must be an array
|
13
|
+
# of host:port pairs. (required)
|
14
|
+
hosts:
|
15
|
+
- localhost:27017
|
16
|
+
options:
|
17
|
+
# Change the default write concern. (default = { w: 1 })
|
18
|
+
#write:
|
19
|
+
# w: 1
|
20
|
+
|
21
|
+
# Change the default read preference. Valid options for mode are: :secondary,
|
22
|
+
# :secondary_preferred, :primary, :primary_preferred, :nearest
|
23
|
+
# (default: primary)
|
24
|
+
#read:
|
25
|
+
# mode: :secondary_preferred
|
26
|
+
|
27
|
+
# The name of the user for authentication.
|
28
|
+
#user: 'user'
|
29
|
+
|
30
|
+
# The password of the user for authentication.
|
31
|
+
#password: 'password'
|
32
|
+
|
33
|
+
# The user's database roles.
|
34
|
+
#roles:
|
35
|
+
# - 'dbOwner'
|
36
|
+
|
37
|
+
# Change the default authentication mechanism. Valid options are: :scram,
|
38
|
+
# :mongodb_cr, :mongodb_x509, and :plain. (default on 3.0 is :scram, default
|
39
|
+
# on 2.4 and 2.6 is :plain)
|
40
|
+
#auth_mech: :scram
|
41
|
+
|
42
|
+
# The database or source to authenticate the user against. (default: admin)
|
43
|
+
#auth_source: admin
|
44
|
+
|
45
|
+
# Force a the driver cluster to behave in a certain manner instead of auto-
|
46
|
+
# discovering. Can be one of: :direct, :replica_set, :sharded. Set to :direct
|
47
|
+
# when connecting to hidden members of a replica set.
|
48
|
+
#connect: :direct
|
49
|
+
|
50
|
+
# Changes the default time in seconds the server monitors refresh their status
|
51
|
+
# via ismaster commands. (default: 10)
|
52
|
+
#heartbeat_frequency: 10
|
53
|
+
|
54
|
+
# The time in seconds for selecting servers for a near read preference. (default: 5)
|
55
|
+
#local_threshold: 5
|
56
|
+
|
57
|
+
# The timeout in seconds for selecting a server for an operation. (default: 30)
|
58
|
+
#server_selection_timeout: 30
|
59
|
+
|
60
|
+
# The maximum number of connections in the connection pool. (default: 5)
|
61
|
+
#max_pool_size: 5
|
62
|
+
|
63
|
+
# The minimum number of connections in the connection pool. (default: 1)
|
64
|
+
#min_pool_size: 1
|
65
|
+
|
66
|
+
# The time to wait, in seconds, in the connection pool for a connection
|
67
|
+
# to be checked in before timing out. (default: 5)
|
68
|
+
#wait_queue_timeout: 5
|
69
|
+
|
70
|
+
# The time to wait to establish a connection before timing out, in seconds.
|
71
|
+
# (default: 5)
|
72
|
+
#connect_timeout: 5
|
73
|
+
|
74
|
+
# The timeout to wait to execute operations on a socket before raising an error.
|
75
|
+
# (default: 5)
|
76
|
+
#socket_timeout: 5
|
77
|
+
|
78
|
+
# The name of the replica set to connect to. Servers provided as seeds that do
|
79
|
+
# not belong to this replica set will be ignored.
|
80
|
+
#replica_set: my_replica_set
|
81
|
+
|
82
|
+
# Whether to connect to the servers via ssl. (default: false)
|
83
|
+
#ssl: true
|
84
|
+
|
85
|
+
# The certificate file used to identify the connection against MongoDB.
|
86
|
+
#ssl_cert: /path/to/my.cert
|
87
|
+
|
88
|
+
# The private keyfile used to identify the connection against MongoDB.
|
89
|
+
# Note that even if the key is stored in the same file as the certificate,
|
90
|
+
# both need to be explicitly specified.
|
91
|
+
#ssl_key: /path/to/my.key
|
92
|
+
|
93
|
+
# A passphrase for the private key.
|
94
|
+
#ssl_key_pass_phrase: password
|
95
|
+
|
96
|
+
# Whether or not to do peer certification validation. (default: false)
|
97
|
+
#ssl_verify: true
|
98
|
+
|
99
|
+
# The file containing a set of concatenated certification authority certifications
|
100
|
+
# used to validate certs passed from the other end of the connection.
|
101
|
+
#ssl_ca_cert: /path/to/ca.cert
|
102
|
+
|
103
|
+
# Configure Mongoid specific options. (optional)
|
104
|
+
options:
|
105
|
+
# Includes the root model name in json serialization. (default: false)
|
106
|
+
#include_root_in_json: false
|
107
|
+
|
108
|
+
# Include the _type field in serialization. (default: false)
|
109
|
+
include_type_for_serialization: true
|
110
|
+
|
111
|
+
# Preload all models in development, needed when models use
|
112
|
+
# inheritance. (default: false)
|
113
|
+
#preload_models: false
|
114
|
+
|
115
|
+
# Raise an error when performing a #find and the document is not found.
|
116
|
+
# (default: true)
|
117
|
+
raise_not_found_error: false
|
118
|
+
|
119
|
+
# Raise an error when defining a scope with the same name as an
|
120
|
+
# existing method. (default: false)
|
121
|
+
scope_overwrite_exception: true
|
122
|
+
|
123
|
+
# Use Active Support's time zone in conversions. (default: true)
|
124
|
+
#use_activesupport_time_zone: true
|
125
|
+
|
126
|
+
# Ensure all times are UTC in the app side. (default: false)
|
127
|
+
#use_utc: false
|
data/spec/db_env.sh
ADDED
data/spec/db_start.sh
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'libis/workflow'
|
3
|
+
require_relative 'test_item'
|
4
|
+
|
5
|
+
class TestDirItem < TestItem
|
6
|
+
include ::Libis::Workflow::Base::DirItem
|
7
|
+
|
8
|
+
def name=(dir)
|
9
|
+
raise RuntimeError, "'#{dir}' is not a directory" unless File.directory? dir
|
10
|
+
super dir
|
11
|
+
end
|
12
|
+
|
13
|
+
def name
|
14
|
+
self.properties[:name] || super
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'libis-tools'
|
3
|
+
require 'libis-workflow'
|
4
|
+
|
5
|
+
require_relative 'test_item'
|
6
|
+
|
7
|
+
class TestFileItem < TestItem
|
8
|
+
include ::Libis::Workflow::Base::FileItem
|
9
|
+
|
10
|
+
def filename=(file)
|
11
|
+
raise RuntimeError, "'#{file}' is not a file" unless File.file? file
|
12
|
+
set_checksum :SHA256, ::Libis::Tools::Checksum.hexdigest(file, :SHA256)
|
13
|
+
super file
|
14
|
+
end
|
15
|
+
|
16
|
+
def name
|
17
|
+
self.properties[:name] || super
|
18
|
+
end
|
19
|
+
|
20
|
+
def filesize
|
21
|
+
properties[:size]
|
22
|
+
end
|
23
|
+
|
24
|
+
def fixity_check(checksum)
|
25
|
+
properties[:checksum] == checksum
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/spec/items.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'backports/rails/string'
|
3
|
+
require 'libis-workflow'
|
4
|
+
|
5
|
+
class CamelizeName < ::Libis::Workflow::Task
|
6
|
+
|
7
|
+
def process(item)
|
8
|
+
return unless (item.is_a?(TestFileItem) || item.is_a?(TestDirItem))
|
9
|
+
item.properties[:name] = item.name.camelize
|
10
|
+
item.save!
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'libis/tools/checksum'
|
3
|
+
|
4
|
+
require 'libis/exceptions'
|
5
|
+
require 'libis-workflow'
|
6
|
+
|
7
|
+
class ChecksumTester < ::Libis::Workflow::Task
|
8
|
+
|
9
|
+
parameter checksum_type: nil,
|
10
|
+
description: 'Checksum type to use.',
|
11
|
+
constraint: ::Libis::Tools::Checksum::CHECKSUM_TYPES.map {|x| x.to_s}
|
12
|
+
parameter checksum_file: nil, description: 'File with checksums of the files.'
|
13
|
+
|
14
|
+
def process(item)
|
15
|
+
return unless item.is_a? TestFileItem
|
16
|
+
|
17
|
+
checksum_type = parameter(:checksum_type)
|
18
|
+
|
19
|
+
if checksum_type.nil?
|
20
|
+
::Libis::Tools::Checksum::CHECKSUM_TYPES.each do |x|
|
21
|
+
test_checksum(item, x) if item.checksum(x)
|
22
|
+
end
|
23
|
+
else
|
24
|
+
test_checksum(item, checksum_type)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_checksum(item, checksum_type)
|
29
|
+
checksum = ::Libis::Tools::Checksum.hexdigest(item.fullpath, checksum_type.to_sym)
|
30
|
+
return if item.checksum(checksum_type) == checksum
|
31
|
+
raise ::Libis::WorkflowError, "Checksum test #{checksum_type} failed for #{item.filepath}"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'libis/exceptions'
|
3
|
+
|
4
|
+
require_relative '../items'
|
5
|
+
|
6
|
+
class CollectFiles < ::Libis::Workflow::Task
|
7
|
+
|
8
|
+
parameter location: '.',
|
9
|
+
description: 'Dir location to start scanning for files.'
|
10
|
+
parameter subdirs: false,
|
11
|
+
description: 'Look for files in subdirs too.'
|
12
|
+
parameter selection: nil,
|
13
|
+
description: 'Only select files that match the given regular expression. Ignored if empty.'
|
14
|
+
|
15
|
+
def process(item)
|
16
|
+
if item.is_a? TestRun
|
17
|
+
add_item(item, parameter(:location))
|
18
|
+
elsif item.is_a? TestDirItem
|
19
|
+
collect_files(item, item.fullpath)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def collect_files(item, dir)
|
24
|
+
glob_string = dir
|
25
|
+
glob_string = File.join(glob_string, '**') if parameter(:subdirs)
|
26
|
+
glob_string = File.join(glob_string, '*')
|
27
|
+
|
28
|
+
Dir.glob(glob_string).select do |x|
|
29
|
+
parameter(:selection) && !parameter(:selection).empty? ? x =~ Regexp.new(parameter(:selection)) : true
|
30
|
+
end.sort.each do |file|
|
31
|
+
next if %w'. ..'.include? file
|
32
|
+
add_item(item, file)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_item(item, file)
|
37
|
+
child = if File.file?(file)
|
38
|
+
TestFileItem.new
|
39
|
+
elsif File.directory?(file)
|
40
|
+
TestDirItem.new
|
41
|
+
else
|
42
|
+
error 'Bad file type encountered: %s', file
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
unless child
|
46
|
+
return
|
47
|
+
end
|
48
|
+
child.filename = file
|
49
|
+
item << child
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/spec/test_job.rb
ADDED