libis-workflow-mongoid 2.0.beta.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 078b1479a71dd3aa0b22ff3bd534fa44ef56d102
4
+ data.tar.gz: 468d080ff339b2a56b7e6e35de062c0ddfb884c0
5
+ SHA512:
6
+ metadata.gz: b93b01ca4a8b305b49c736e36bcd1a6e3e2dd0ed73e09c675450c26d61847e30ee87f6699ace563c1a6ec3cfaab85354b895dd4f605a3608a557f3f778e77009
7
+ data.tar.gz: b20e762041669612e0b7d808ff661910d26556e82be0830b280f3da8584b4a9b8a4ff1ebf1cb0ad5036c461dea99bf52ad771909f5d815361f3b7c7f722d5de9
data/.gitignore ADDED
@@ -0,0 +1,38 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ Gemfile.lock
30
+ .ruby-version
31
+ .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
35
+
36
+ .idea
37
+ projectFilesBackup
38
+ spec/data
@@ -0,0 +1,31 @@
1
+ db = db.getSiblingDB("admin");
2
+
3
+ db.createUser(
4
+ {
5
+ "user" : "useradmin",
6
+ "pwd" : "useradmin",
7
+ "roles" : [
8
+ {
9
+ "role" : "userAdminAnyDatabase",
10
+ "db" : "admin"
11
+ }
12
+ ]
13
+ }
14
+ );
15
+
16
+ db.auth("useradmin", "useradmin");
17
+
18
+ db = db.getSiblingDB("workflow_test");
19
+
20
+ db.createUser(
21
+ {
22
+ "user" : "test",
23
+ "pwd" : "abc123",
24
+ "roles" : [
25
+ {
26
+ "role" : "readWriteAnyDatabase",
27
+ "db" : "admin"
28
+ }
29
+ ]
30
+ }
31
+ );
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ OLD_DIR=`pwd`
3
+ cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null
4
+ # Creates not-authorized problems on MongoDB 3.0.2 on my machine
5
+ # Using authorization-less code for now. To be investigated later ...
6
+ # mongo create_users.js
7
+ cd "${OLD_DIR}"
data/.travis.yml ADDED
@@ -0,0 +1,34 @@
1
+ language: ruby
2
+ cache: bundler
3
+ branches:
4
+ only:
5
+ - master
6
+ rvm:
7
+ - 1.9.3
8
+ - 2.1.0
9
+ - ruby-head
10
+ - jruby-19mode
11
+ jdk:
12
+ - openjdk7
13
+ - oraclejdk7
14
+ - oraclejdk8
15
+ env:
16
+ - MONGOID_VERSION=3
17
+ - MONGOID_VERSION=4
18
+ matrix:
19
+ exclude:
20
+ - rvm: 1.9.3
21
+ jdk: oraclejdk7
22
+ - rvm: 1.9.3
23
+ jdk: oraclejdk8
24
+ - rvm: 2.1.0
25
+ jdk: oraclejdk7
26
+ - rvm: 2.1.0
27
+ jdk: oraclejdk8
28
+ - rvm: ruby-head
29
+ jdk: oraclejdk7
30
+ - rvm: ruby-head
31
+ jdk: oraclejdk8
32
+ services:
33
+ - mongodb
34
+ before_script: ./.travis/db_prepare.sh
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec name: 'libis-workflow-mongoid', development_group: :test
4
+
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 LIBIS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,8 @@
1
+ [![Build Status](https://travis-ci.org/libis/workflow-mongoid.svg?branch=master)](https://travis-ci.org/libis/workflow-mongoid)
2
+ [![Coverage Status](https://coveralls.io/repos/libis/workflow-mongoid/badge.png)](https://coveralls.io/r/libis/workflow-monoid)
3
+ [![status](https://sourcegraph.com/api/repos/github.com/Kris-LIBIS/workflow-mongoid/.badges/status.png)](https://sourcegraph.com/github.com/Kris-LIBIS/workflow-mongoid)
4
+
5
+ workflow-mongoid
6
+ ================
7
+
8
+ Mongoid persistence for the workflow framework
data/Rakefile ADDED
@@ -0,0 +1,7 @@
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
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ require 'mongoid'
3
+ require 'mongoid/document'
4
+ require 'mongoid_indifferent_access'
5
+
6
+ module Libis
7
+ module Workflow
8
+ module Mongoid
9
+
10
+ module Base
11
+
12
+ def self.included(klass)
13
+ klass.class_eval do
14
+ include ::Mongoid::Document
15
+ include ::Mongoid::Timestamps
16
+ include ::Mongoid::Extensions::Hash::IndifferentAccess
17
+ index created_at: 1
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+ require 'singleton'
3
+ require 'mongoid'
4
+
5
+ require 'libis/workflow/config'
6
+ require 'libis/workflow/mongoid/run'
7
+
8
+ module Libis
9
+ module Workflow
10
+ module Mongoid
11
+
12
+ class Config
13
+ include Singleton
14
+
15
+ def database_connect(config_file = './mongoid.yml', environment = nil)
16
+ ::Mongoid.load! config_file, environment
17
+ end
18
+
19
+ def method_missing(name, *args, &block)
20
+ ::Libis::Workflow::Config.instance.send(name, *args, &block)
21
+ end
22
+
23
+ def self.const_missing(name)
24
+ return ::Libis::Workflow::Config.const_get(name) if ::Libis::Workflow::Config.const_defined?(name)
25
+ super(name)
26
+ end
27
+
28
+ private
29
+
30
+ def initialize
31
+ ::Libis::Workflow::Config.instance
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,69 @@
1
+ # encoding: utf-8
2
+ require 'fileutils'
3
+
4
+ require 'libis/workflow/base/run'
5
+ require 'libis/workflow/mongoid/work_item_base'
6
+
7
+ module Libis
8
+ module Workflow
9
+ module Mongoid
10
+
11
+ module Run
12
+ # extend ActiveSupport::Concern
13
+
14
+ def self.included(klass)
15
+ klass.class_eval do
16
+ include ::Libis::Workflow::Base::Run
17
+ include ::Libis::Workflow::Mongoid::WorkItemBase
18
+
19
+ store_in collection: 'workflow_runs'
20
+
21
+ attr_accessor :tasks
22
+
23
+ field :start_date, type: Time, default: -> { Time.now }
24
+
25
+ set_callback(:destroy, :before) do |document|
26
+ wd = document.work_dir
27
+ FileUtils.rmtree wd if Dir.exist? wd
28
+ end
29
+
30
+ index start_date: 1
31
+
32
+ def klass.workflow_class(wf_klass)
33
+ belongs_to :workflow, inverse_of: :workflow_runs, class_name: wf_klass.to_s
34
+ end
35
+
36
+ def klass.item_class(item_klass)
37
+ has_many :items, inverse_of: :run, class_name: item_klass.to_s,
38
+ dependent: :destroy, autosave: true, order: :created_at.asc
39
+ end
40
+ end
41
+ end
42
+
43
+ def run(opts = {})
44
+ self.tasks = []
45
+ self.items = []
46
+ # noinspection RubySuperCallWithoutSuperclassInspection
47
+ super opts
48
+ end
49
+
50
+ def restart(taskname)
51
+ self.tasks = []
52
+ self.tasks = self.workflow.tasks(self)
53
+ configure_tasks self.options
54
+ self.status = :RESTARTED
55
+ self.tasks.each do |task|
56
+ next if self.status == :RESTARTED && task.name != taskname
57
+ task.run self
58
+ end
59
+ end
60
+
61
+ def parent
62
+ nil
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ module Libis
4
+ module Workflow
5
+ module Mongoid
6
+ VERSION = '2.0.beta.5' unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+ require 'libis/workflow/mongoid/work_item_base'
3
+
4
+ module Libis
5
+ module Workflow
6
+ module Mongoid
7
+
8
+ module WorkItem
9
+
10
+ def self.included(klass)
11
+ klass.class_eval do
12
+ include Libis::Workflow::Mongoid::WorkItemBase
13
+
14
+ store_in collection: 'workflow_items'
15
+
16
+ has_many :items, inverse_of: :parent, class_name: klass.to_s,
17
+ dependent: :destroy, autosave: true, order: :created_at.asc
18
+ belongs_to :parent, inverse_of: :items, class_name: klass.to_s
19
+
20
+ def klass.run_class(run_klass)
21
+ belongs_to :run, inverse_of: :items, class_name: run_klass.to_s
22
+ end
23
+
24
+
25
+ end
26
+ end
27
+
28
+ def parent
29
+ self[:parent] || self[:run]
30
+ end
31
+
32
+ def get_run
33
+ p = self[:parent]
34
+ p ? p.get_run : self[:run]
35
+ end
36
+
37
+ def get_root
38
+ self[:parent].get_root rescue self
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ require 'libis-workflow'
3
+ require 'libis/workflow/mongoid/base'
4
+
5
+ module Libis
6
+ module Workflow
7
+ module Mongoid
8
+
9
+ module WorkItemBase
10
+
11
+ def self.included(klass)
12
+ klass.class_eval do
13
+ include Libis::Workflow::WorkItem
14
+ include Libis::Workflow::Mongoid::Base
15
+
16
+ field :options, type: Hash, default: -> { Hash.new }
17
+ field :properties, type: Hash, default: -> { Hash.new }
18
+
19
+ field :log_history, type: Array, default: -> { Array.new }
20
+ field :status_log, type: Array, default: -> { Array.new }
21
+
22
+ field :summary, type: Hash, default: -> { Hash.new }
23
+ end
24
+
25
+ end
26
+
27
+ def item_count
28
+ self.items.size
29
+ end
30
+
31
+ def add_item(item)
32
+ return self unless item and item.is_a? Libis::Workflow::Mongoid::WorkItem
33
+ self.items << item
34
+ self.save!
35
+ self
36
+ end
37
+
38
+ alias :<< :add_item
39
+
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ require 'libis/workflow/worker'
4
+
5
+ module Libis
6
+ module Workflow
7
+ module Mongoid
8
+
9
+ class Worker < Libis::Workflow::Worker
10
+
11
+ def get_workflow(workflow_config)
12
+ workflow_name = workflow_config[:name] if workflow_config.is_a? Hash
13
+ workflow_name ||= workflow_config.to_s
14
+ workflow = ::Libis::Workflow::Mongoid.find(name: workflow_name).first
15
+ raise RuntimeError.new "Workflow #{workflow_name} not found" unless workflow.is_a? ::Libis::Workflow::Mongoid::Workflow
16
+ workflow
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ require 'libis/workflow/base/workflow'
4
+ require 'libis/workflow/mongoid/base'
5
+
6
+ module Libis
7
+ module Workflow
8
+ module Mongoid
9
+
10
+ module Workflow
11
+
12
+ def self.included(klass)
13
+ klass.class_eval do
14
+ include ::Libis::Workflow::Base::Workflow
15
+ include ::Libis::Workflow::Mongoid::Base
16
+
17
+ store_in collection: 'workflow_defintions'
18
+
19
+ field :name, type: String
20
+ field :description, type: String
21
+ field :config, type: Hash, default: -> { Hash.new }
22
+
23
+ index({name: 1}, {unique: 1})
24
+
25
+ def klass.run_class(run_klass)
26
+ has_many :workflow_runs, inverse_of: :workflow, class_name: run_klass.to_s,
27
+ dependent: :destroy, autosave: true, order: :created_at.asc
28
+ end
29
+
30
+ def create_run_object
31
+ # noinspection RubyResolve
32
+ self.workflow_runs.build
33
+ end
34
+
35
+ def restart(id, task = nil)
36
+ # noinspection RubyResolve
37
+ run_object = self.workflow_runs.select { |run| run.id == id }
38
+ raise WorkflowError, "Run #{id} not found" unless run_object
39
+ run_object.restart task
40
+ run_object
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ require 'libis-workflow'
4
+
5
+ module Libis
6
+ module Workflow
7
+ module Mongoid
8
+
9
+ autoload :Config, 'libis/workflow/mongoid/config'
10
+ autoload :Base, 'libis/workflow/mongoid/base'
11
+ autoload :Workflow, 'libis/workflow/mongoid/workflow'
12
+ autoload :WorkItem, 'libis/workflow/mongoid/work_item'
13
+ autoload :Run, 'libis/workflow/mongoid/run'
14
+ autoload :Worker, 'libis/workflow/mongoid/worker'
15
+
16
+ def self.configure
17
+ yield ::Libis::Workflow::Mongoid::Config.instance
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require 'libis/workflow/mongoid'
@@ -0,0 +1,44 @@
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
+ mv_env = ENV['MONGOID_VERSION'] || '4.0'
9
+ mongoid_version = mv_env == 'master' ? '{github: "mongoid/mongoid"}' : "~> #{mv_env}"
10
+
11
+ Gem::Specification.new do |gem|
12
+ gem.name = 'libis-workflow-mongoid'
13
+ gem.version = ::Libis::Workflow::Mongoid::VERSION
14
+ gem.date = Date.today.to_s
15
+
16
+ gem.summary = %q{Mongoid persistence for the LIBIS Workflow framework.}
17
+ gem.description = %q{Class implementations that use Mongoid storage for the LIBIS Workflow framework.}
18
+
19
+ gem.author = 'Kris Dekeyser'
20
+ gem.email = 'kris.dekeyser@libis.be'
21
+ gem.homepage = 'https://github.com/libis/workflow-mongoid'
22
+ gem.license = 'MIT'
23
+
24
+ gem.files = `git ls-files -z`.split("\0")
25
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
26
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
27
+
28
+ gem.require_paths = ['lib']
29
+
30
+ gem.add_runtime_dependency 'libis-workflow', '~> 2.0.beta'
31
+ gem.add_runtime_dependency 'mongoid', mongoid_version
32
+ gem.add_runtime_dependency 'mongoid-indifferent-access'
33
+
34
+ gem.add_runtime_dependency 'sidekiq'
35
+ if mv_env =~ /^3\./
36
+ gem.add_runtime_dependency 'kiqstand'
37
+ end
38
+
39
+ gem.add_development_dependency 'bundler', '~> 1.6'
40
+ gem.add_development_dependency 'rake'
41
+ gem.add_development_dependency 'rspec'
42
+ gem.add_development_dependency 'coveralls'
43
+
44
+ end
data/mongoid.yml ADDED
@@ -0,0 +1,19 @@
1
+ # Mongoid Configuration for Travis CI
2
+ # ===================================
3
+
4
+ default:
5
+
6
+ test:
7
+ options:
8
+ include_type_for_serialization: true
9
+ include_root_in_json: false
10
+ preload_models: false
11
+ raise_not_found_error: false
12
+ scope_overwrite_exception: true
13
+ use_activesupport_time_zone: true
14
+ use_utc: false
15
+ sessions:
16
+ default:
17
+ database: workflow_test
18
+ hosts:
19
+ - localhost:27017
data/spec/db_env.sh ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+ export DB_HOST="kahana.mongohq.com:10053"
3
+ export DB_HOST="localhost:27017"
4
+ export DB_USER="test"
5
+ export DB_PASS="abc123"
data/spec/db_start.sh ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+ cd `dirname $0`
3
+ mkdir -p ./data/db
4
+ /opt/mongodb/bin/mongod --dbpath ./data/db
5
+
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+ require_relative 'test_item'
3
+
4
+ class TestDirItem < TestItem
5
+ include ::Libis::Workflow::DirItem
6
+
7
+ def name=(dir)
8
+ raise RuntimeError, "'#{dir}' is not a directory" unless File.directory? dir
9
+ super dir
10
+ end
11
+
12
+ def name
13
+ self.properties[:name] || super
14
+ end
15
+
16
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ require 'libis-tools'
3
+
4
+ require_relative 'test_item'
5
+
6
+ class TestFileItem < TestItem
7
+ include ::Libis::Workflow::FileItem
8
+
9
+ def filename=(file)
10
+ raise RuntimeError, "'#{file}' is not a file" unless File.file? file
11
+ set_checksum :SHA256, ::Libis::Tools::Checksum.hexdigest(file, :SHA256)
12
+ super file
13
+ end
14
+
15
+ def name
16
+ self.properties[:name] || super
17
+ end
18
+
19
+ def filesize
20
+ properties[:size]
21
+ end
22
+
23
+ def fixity_check(checksum)
24
+ properties[:checksum] == checksum
25
+ end
26
+
27
+ end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ require 'libis/workflow/mongoid/work_item'
4
+
5
+ class TestItem
6
+ include Libis::Workflow::Mongoid::WorkItem
7
+ run_class 'TestRun'
8
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+ require 'libis-workflow-mongoid'
3
+
4
+ class TestRun
5
+ include ::Libis::Workflow::Mongoid::Run
6
+
7
+ item_class 'TestItem'
8
+ workflow_class 'TestWorkflow'
9
+
10
+ def name; 'TestRun'; end
11
+
12
+ end
data/spec/items.rb ADDED
@@ -0,0 +1,3 @@
1
+ require_relative 'items/test_dir_item'
2
+ require_relative 'items/test_file_item'
3
+ require_relative 'items/test_run'
@@ -0,0 +1,8 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'bundler/setup'
5
+ Bundler.setup
6
+
7
+ require 'rspec'
8
+ require 'libis-workflow-mongoid'
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+ require 'backports/rails/string'
3
+
4
+ require 'libis/workflow/workitems'
5
+
6
+ class CamelizeName < ::Libis::Workflow::Task
7
+
8
+ def process(item)
9
+ return unless (item.is_a?(TestFileItem) || item.is_a?(TestDirItem))
10
+ item.properties[:name] = item.name.camelize
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/workitems'
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 = options[: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,48 @@
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, options[: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 options[:subdirs]
26
+ glob_string = File.join(glob_string, '*')
27
+
28
+ Dir.glob(glob_string).select do |x|
29
+ options[:selection] && !options[:selection].empty? ? x =~ Regexp.new(options[: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
+ Item.new
43
+ end
44
+ child.filename = file
45
+ item << child
46
+ end
47
+
48
+ end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ require 'libis/workflow/mongoid/workflow'
4
+
5
+ class TestWorkflow
6
+ include ::Libis::Workflow::Mongoid::Workflow
7
+ run_class 'TestRun'
8
+ end
@@ -0,0 +1,212 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rspec'
4
+ require 'stringio'
5
+
6
+ require 'libis-workflow-mongoid'
7
+
8
+ require_relative 'spec_helper'
9
+ require_relative 'test_workflow'
10
+ require_relative 'items'
11
+
12
+ DIRNAME = 'spec/items'
13
+
14
+ describe 'TestWorkflow' do
15
+
16
+ before :all do
17
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
18
+
19
+
20
+ @logoutput = StringIO.new
21
+
22
+ ::Libis::Workflow::Mongoid.configure do |cfg|
23
+ cfg.itemdir = File.join(File.dirname(__FILE__), 'items')
24
+ cfg.taskdir = File.join(File.dirname(__FILE__), 'tasks')
25
+ cfg.workdir = File.join(File.dirname(__FILE__), 'work')
26
+ cfg.logger = Logger.new @logoutput
27
+ cfg.set_formatter
28
+ cfg.logger.level = Logger::DEBUG
29
+ cfg.database_connect 'mongoid.yml', :test
30
+ end
31
+
32
+ TestWorkflow.create_indexes
33
+ TestRun.create_indexes
34
+ TestFileItem.create_indexes
35
+ TestDirItem.create_indexes
36
+
37
+ TestWorkflow.each { |wf| wf.destroy }
38
+
39
+ @workflow = TestWorkflow.new
40
+ @workflow.configure(
41
+ name: 'TestWorkflow',
42
+ description: 'Workflow for testing',
43
+ tasks: [
44
+ {class: 'CollectFiles', recursive: true},
45
+ {
46
+ name: 'ProcessFiles',
47
+ subitems: true,
48
+ tasks: [
49
+ {class: 'ChecksumTester', recursive: true},
50
+ {class: 'CamelizeName', recursive: true}
51
+ ]
52
+ }
53
+ ],
54
+ input: {
55
+ dirname: {default: '.', propagate_to: 'CollectFiles#location'},
56
+ checksum_type: {default: 'SHA1', propagate_to: 'ProcessFiles/ChecksumTester'}
57
+ }
58
+ )
59
+ @workflow.save
60
+
61
+ # noinspection RubyStringKeysInHashInspection
62
+ @run = @workflow.run(dirname: DIRNAME, checksum_type: 'SHA256')
63
+
64
+ end
65
+
66
+ it 'should contain three tasks' do
67
+
68
+ expect(@workflow.config[:tasks].size).to eq 3
69
+ expect(@workflow.config[:tasks].first[:class]).to eq 'CollectFiles'
70
+ expect(@workflow.config[:tasks].last[:class]).to eq '::Libis::Workflow::Tasks::Analyzer'
71
+
72
+ end
73
+
74
+ it 'should camelize the workitem name' do
75
+
76
+ expect(@run.options[:dirname]).to eq DIRNAME
77
+ expect(@run.items.count).to eq 1
78
+ expect(@run.items.first.class).to eq TestDirItem
79
+ expect(@run.items.first.count).to eq 4
80
+ expect(@run.items.first.first.class).to eq TestFileItem
81
+
82
+ @run.items.first.each_with_index do |x, i|
83
+ expect(x.name).to eq %w'TestDirItem.rb TestFileItem.rb TestItem.rb TestRun.rb'[i]
84
+ end
85
+ end
86
+
87
+ it 'should return expected debug output' do
88
+
89
+ sample_out = <<STR
90
+ DEBUG -- CollectFiles - TestRun : Started
91
+ DEBUG -- CollectFiles - TestRun : Processing subitem (1/1): items
92
+ DEBUG -- CollectFiles - items : Started
93
+ DEBUG -- CollectFiles - items : Processing subitem (1/4): test_dir_item.rb
94
+ DEBUG -- CollectFiles - items/test_dir_item.rb : Started
95
+ DEBUG -- CollectFiles - items/test_dir_item.rb : Completed
96
+ DEBUG -- CollectFiles - items : Processing subitem (2/4): test_file_item.rb
97
+ DEBUG -- CollectFiles - items/test_file_item.rb : Started
98
+ DEBUG -- CollectFiles - items/test_file_item.rb : Completed
99
+ DEBUG -- CollectFiles - items : Processing subitem (3/4): test_item.rb
100
+ DEBUG -- CollectFiles - items/test_item.rb : Started
101
+ DEBUG -- CollectFiles - items/test_item.rb : Completed
102
+ DEBUG -- CollectFiles - items : Processing subitem (4/4): test_run.rb
103
+ DEBUG -- CollectFiles - items/test_run.rb : Started
104
+ DEBUG -- CollectFiles - items/test_run.rb : Completed
105
+ DEBUG -- CollectFiles - items : 4 of 4 subitems passed
106
+ DEBUG -- CollectFiles - items : Completed
107
+ DEBUG -- CollectFiles - TestRun : 1 of 1 subitems passed
108
+ DEBUG -- CollectFiles - TestRun : Completed
109
+ DEBUG -- ProcessFiles - TestRun : Started
110
+ DEBUG -- ProcessFiles - TestRun : Processing subitem (1/1): items
111
+ DEBUG -- ProcessFiles - items : Started
112
+ DEBUG -- ProcessFiles - items : Running subtask (1/2): ChecksumTester
113
+ DEBUG -- ProcessFiles/ChecksumTester - items : Started
114
+ DEBUG -- ProcessFiles/ChecksumTester - items : Processing subitem (1/4): test_dir_item.rb
115
+ DEBUG -- ProcessFiles/ChecksumTester - items/test_dir_item.rb : Started
116
+ DEBUG -- ProcessFiles/ChecksumTester - items/test_dir_item.rb : Completed
117
+ DEBUG -- ProcessFiles/ChecksumTester - items : Processing subitem (2/4): test_file_item.rb
118
+ DEBUG -- ProcessFiles/ChecksumTester - items/test_file_item.rb : Started
119
+ DEBUG -- ProcessFiles/ChecksumTester - items/test_file_item.rb : Completed
120
+ DEBUG -- ProcessFiles/ChecksumTester - items : Processing subitem (3/4): test_item.rb
121
+ DEBUG -- ProcessFiles/ChecksumTester - items/test_item.rb : Started
122
+ DEBUG -- ProcessFiles/ChecksumTester - items/test_item.rb : Completed
123
+ DEBUG -- ProcessFiles/ChecksumTester - items : Processing subitem (4/4): test_run.rb
124
+ DEBUG -- ProcessFiles/ChecksumTester - items/test_run.rb : Started
125
+ DEBUG -- ProcessFiles/ChecksumTester - items/test_run.rb : Completed
126
+ DEBUG -- ProcessFiles/ChecksumTester - items : 4 of 4 subitems passed
127
+ DEBUG -- ProcessFiles/ChecksumTester - items : Completed
128
+ DEBUG -- ProcessFiles - items : Running subtask (2/2): CamelizeName
129
+ DEBUG -- ProcessFiles/CamelizeName - items : Started
130
+ DEBUG -- ProcessFiles/CamelizeName - Items : Processing subitem (1/4): test_dir_item.rb
131
+ DEBUG -- ProcessFiles/CamelizeName - Items/test_dir_item.rb : Started
132
+ DEBUG -- ProcessFiles/CamelizeName - Items/TestDirItem.rb : Completed
133
+ DEBUG -- ProcessFiles/CamelizeName - Items : Processing subitem (2/4): test_file_item.rb
134
+ DEBUG -- ProcessFiles/CamelizeName - Items/test_file_item.rb : Started
135
+ DEBUG -- ProcessFiles/CamelizeName - Items/TestFileItem.rb : Completed
136
+ DEBUG -- ProcessFiles/CamelizeName - Items : Processing subitem (3/4): test_item.rb
137
+ DEBUG -- ProcessFiles/CamelizeName - Items/test_item.rb : Started
138
+ DEBUG -- ProcessFiles/CamelizeName - Items/TestItem.rb : Completed
139
+ DEBUG -- ProcessFiles/CamelizeName - Items : Processing subitem (4/4): test_run.rb
140
+ DEBUG -- ProcessFiles/CamelizeName - Items/test_run.rb : Started
141
+ DEBUG -- ProcessFiles/CamelizeName - Items/TestRun.rb : Completed
142
+ DEBUG -- ProcessFiles/CamelizeName - Items : 4 of 4 subitems passed
143
+ DEBUG -- ProcessFiles/CamelizeName - Items : Completed
144
+ DEBUG -- ProcessFiles - Items : Completed
145
+ DEBUG -- ProcessFiles - TestRun : 1 of 1 subitems passed
146
+ DEBUG -- ProcessFiles - TestRun : Completed
147
+ STR
148
+ sample_out = sample_out.lines.to_a
149
+ output = @logoutput.string.lines
150
+
151
+ expect(sample_out.count).to eq output.count
152
+ output.each_with_index do |o, i|
153
+ expect(o[/(?<=\] ).*/]).to eq sample_out[i].strip
154
+ end
155
+
156
+ expect(@run.summary['DEBUG']).to eq 57
157
+ expect(@run.log_history.count).to eq 8
158
+ expect(@run.status_log.count).to eq 6
159
+ expect(@run.items.first.log_history.count).to eq 25
160
+ expect(@run.items.first.status_log.count).to eq 8
161
+
162
+ end
163
+
164
+ it 'find workflow' do
165
+ workflow = TestWorkflow.first
166
+ expect(workflow.nil?).to eq false
167
+ expect(workflow.name).to eq 'TestWorkflow'
168
+ expect(workflow.description).to eq 'Workflow for testing'
169
+ expect(workflow.input.count).to eq 2
170
+ expect(workflow.input[:dirname][:default]).to eq '.'
171
+ expect(workflow.config[:tasks].count).to eq 3
172
+ expect(workflow.config[:tasks][0][:class]).to eq 'CollectFiles'
173
+ expect(workflow.config[:tasks][0][:recursive]).to eq true
174
+ expect(workflow.config[:tasks][1][:name]).to eq 'ProcessFiles'
175
+ expect(workflow.config[:tasks][1][:subitems]).to eq true
176
+ expect(workflow.config[:tasks][1][:tasks].count).to eq 2
177
+ expect(workflow.config[:tasks][1][:tasks][0][:class]).to eq 'ChecksumTester'
178
+ expect(workflow.config[:tasks][1][:tasks][0][:recursive]).to eq true
179
+ expect(workflow.config[:tasks][1][:tasks][1][:class]).to eq 'CamelizeName'
180
+ expect(workflow.config[:tasks][1][:tasks][1][:recursive]).to eq true
181
+ expect(workflow.config[:tasks][2][:class]).to eq '::Libis::Workflow::Tasks::Analyzer'
182
+ end
183
+
184
+ # noinspection RubyResolve
185
+ it 'find run' do
186
+ workflow = TestWorkflow.first
187
+ expect(workflow.workflow_runs.count).to be > 0
188
+ run = workflow.workflow_runs.first
189
+ expect(run.is_a? TestRun).to eq true
190
+ expect(run.nil?).to eq false
191
+ expect(run.options[:dirname]).to eq 'spec/items'
192
+ expect(run.properties[:ingest_failed]).to eq false
193
+ expect(run.log_history.count).to eq 8
194
+ expect(run.status_log.count).to eq 6
195
+ expect(run.summary[:DEBUG]).to eq 57
196
+ end
197
+
198
+ # noinspection RubyResolve
199
+ it 'find first item' do
200
+ workflow = TestWorkflow.first
201
+ expect(workflow.workflow_runs.first.items.count).to be > 0
202
+ item = workflow.workflow_runs.first.items.first
203
+ expect(item.nil?).to eq false
204
+ expect(item.is_a? TestDirItem).to eq true
205
+ expect(item.properties[:name]).to eq 'Items'
206
+ expect(item.properties[:ingest_failed]).to eq false
207
+ expect(item.log_history.count).to eq 25
208
+ expect(item.status_log.count).to eq 8
209
+ expect(item.summary[:DEBUG]).to eq 49
210
+ end
211
+
212
+ end
metadata ADDED
@@ -0,0 +1,202 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libis-workflow-mongoid
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.beta.5
5
+ platform: ruby
6
+ authors:
7
+ - Kris Dekeyser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: libis-workflow
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.beta
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.beta
27
+ - !ruby/object:Gem::Dependency
28
+ name: mongoid
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mongoid-indifferent-access
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sidekiq
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Class implementations that use Mongoid storage for the LIBIS Workflow
126
+ framework.
127
+ email: kris.dekeyser@libis.be
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".travis.yml"
134
+ - ".travis/create_users.js"
135
+ - ".travis/db_prepare.sh"
136
+ - Gemfile
137
+ - LICENSE
138
+ - README.md
139
+ - Rakefile
140
+ - lib/libis-workflow-mongoid.rb
141
+ - lib/libis/workflow/mongoid.rb
142
+ - lib/libis/workflow/mongoid/base.rb
143
+ - lib/libis/workflow/mongoid/config.rb
144
+ - lib/libis/workflow/mongoid/run.rb
145
+ - lib/libis/workflow/mongoid/version.rb
146
+ - lib/libis/workflow/mongoid/work_item.rb
147
+ - lib/libis/workflow/mongoid/work_item_base.rb
148
+ - lib/libis/workflow/mongoid/worker.rb
149
+ - lib/libis/workflow/mongoid/workflow.rb
150
+ - libis-workflow-mongoid.gemspec
151
+ - mongoid.yml
152
+ - spec/db_env.sh
153
+ - spec/db_start.sh
154
+ - spec/items.rb
155
+ - spec/items/test_dir_item.rb
156
+ - spec/items/test_file_item.rb
157
+ - spec/items/test_item.rb
158
+ - spec/items/test_run.rb
159
+ - spec/spec_helper.rb
160
+ - spec/tasks/camelize_name.rb
161
+ - spec/tasks/checksum_tester.rb
162
+ - spec/tasks/collect_files.rb
163
+ - spec/test_workflow.rb
164
+ - spec/workflow_spec.rb
165
+ homepage: https://github.com/libis/workflow-mongoid
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">"
181
+ - !ruby/object:Gem::Version
182
+ version: 1.3.1
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.4.6
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: Mongoid persistence for the LIBIS Workflow framework.
189
+ test_files:
190
+ - spec/db_env.sh
191
+ - spec/db_start.sh
192
+ - spec/items.rb
193
+ - spec/items/test_dir_item.rb
194
+ - spec/items/test_file_item.rb
195
+ - spec/items/test_item.rb
196
+ - spec/items/test_run.rb
197
+ - spec/spec_helper.rb
198
+ - spec/tasks/camelize_name.rb
199
+ - spec/tasks/checksum_tester.rb
200
+ - spec/tasks/collect_files.rb
201
+ - spec/test_workflow.rb
202
+ - spec/workflow_spec.rb