lyber-core 5.5.1 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/lyber_core.rb +1 -1
- data/lib/lyber_core/return_state.rb +0 -12
- data/lib/lyber_core/robot.rb +31 -43
- data/lib/lyber_core/workflow.rb +43 -0
- metadata +4 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0786ae4b4aa512ea86d9a147d4002d141fc2658e8f52b533056c658dee6d727e'
|
4
|
+
data.tar.gz: fd8b91265cbf0f5aa5c456d2f7edd88c4d7fd8c4fad019bd99df403021e7dd39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c250695948c1c111c181886b8d03ffe23475a8c5ce020da62f67782710a682ac0f9cbbe1952e1efe36eb9d20363c63049477a01b47763770862ba7e200e1da2
|
7
|
+
data.tar.gz: 665ab707ba5e5603440dc1c9ee3b8f1b0ac67dc7bc213f441baeb1525070f8e3f1b2eaee317ad3d283216ba3d304574b898b2bd92c11d42182545c906be3d7cf
|
data/README.md
CHANGED
@@ -53,13 +53,13 @@ module Robots
|
|
53
53
|
obj = Dor::Item.find(druid)
|
54
54
|
if some_logic_here_to_determine_if_shelving_occurs
|
55
55
|
obj.shelve
|
56
|
-
return LyberCore::Robot::ReturnState.
|
57
|
-
# return LyberCore::Robot::ReturnState.new(
|
56
|
+
return LyberCore::Robot::ReturnState.new(status: 'completed') # set the final state to completed
|
57
|
+
# return LyberCore::Robot::ReturnState.new(status: 'completed', note: 'some custom note to pass back to workflow') # set the final state to completed with a custom note
|
58
58
|
|
59
59
|
else
|
60
60
|
# just return skipped if we did nothing
|
61
|
-
return LyberCore::Robot::ReturnState.
|
62
|
-
# return LyberCore::Robot::ReturnState.new(
|
61
|
+
return LyberCore::Robot::ReturnState.new(status: 'skipped') # set the final state to skipped
|
62
|
+
# return LyberCore::Robot::ReturnState.new(status: 'skipped', note: 'some custom note to pass back to workflow') # set the final state to skipped with a custom note
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
data/lib/lyber_core.rb
CHANGED
@@ -11,18 +11,6 @@ module LyberCore
|
|
11
11
|
ALLOWED_RETURN_STATES = %w[completed skipped waiting].freeze
|
12
12
|
DEFAULT_RETURN_STATE = 'completed'
|
13
13
|
|
14
|
-
def self.SKIPPED
|
15
|
-
new(status: 'skipped')
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.COMPLETED
|
19
|
-
new(status: 'completed')
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.WAITING
|
23
|
-
new(status: 'waiting')
|
24
|
-
end
|
25
|
-
|
26
14
|
def initialize(params = {})
|
27
15
|
self.status = params[:status] || DEFAULT_RETURN_STATE
|
28
16
|
self.note = params[:note] || ''
|
data/lib/lyber_core/robot.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'benchmark'
|
4
|
-
require 'active_support'
|
5
|
-
require 'active_support/core_ext'
|
6
|
-
require 'active_support/core_ext/string/inflections' # camelcase
|
7
4
|
|
8
5
|
module LyberCore
|
9
6
|
module Robot
|
@@ -21,56 +18,36 @@ module LyberCore
|
|
21
18
|
end
|
22
19
|
end
|
23
20
|
|
24
|
-
# Converts a given step to the Robot class name
|
25
|
-
# Examples:
|
26
|
-
#
|
27
|
-
# - `dor:assemblyWF:jp2-create` into `Robots::DorRepo::Assembly::Jp2Create`
|
28
|
-
# - `dor:gisAssemblyWF:start-assembly-workflow` into `Robots::DorRepo::GisAssembly::StartAssemblyWorkflow`
|
29
|
-
# - `dor:etdSubmitWF:binder-transfer` into `Robots:DorRepo::EtdSubmit::BinderTransfer`
|
30
|
-
#
|
31
|
-
# @param [String] step. fully qualified step name, e.g., `dor:accessionWF:descriptive-metadata`
|
32
|
-
# @param [Hash] opts
|
33
|
-
# @option :repo_suffix defaults to `Repo`
|
34
|
-
# @return [String] The class name for the robot, e.g., `Robots::DorRepo::Accession:DescriptiveMetadata`
|
35
|
-
def self.step_to_classname(step, opts = {})
|
36
|
-
# generate the robot job class name
|
37
|
-
opts[:repo_suffix] ||= 'Repo'
|
38
|
-
r, w, s = step.split(/:/, 3)
|
39
|
-
[
|
40
|
-
'Robots',
|
41
|
-
r.camelcase + opts[:repo_suffix], # 'Dor' conflicts with dor-services
|
42
|
-
w.sub('WF', '').camelcase,
|
43
|
-
s.tr('-', '_').camelcase
|
44
|
-
].join('::')
|
45
|
-
end
|
46
|
-
|
47
21
|
attr_accessor :check_queued_status
|
48
|
-
attr_reader :
|
22
|
+
attr_reader :workflow_name, :process
|
49
23
|
|
50
|
-
def initialize(
|
24
|
+
def initialize(workflow_name, process, check_queued_status: true)
|
51
25
|
Signal.trap('QUIT') { puts "#{Process.pid} ignoring SIGQUIT" } # SIGQUIT ignored to let the robot finish
|
52
|
-
@repo = repo
|
53
26
|
@workflow_name = workflow_name
|
54
|
-
@
|
55
|
-
@check_queued_status =
|
56
|
-
|
27
|
+
@process = process
|
28
|
+
@check_queued_status = check_queued_status
|
29
|
+
end
|
30
|
+
|
31
|
+
def workflow_service
|
32
|
+
raise 'The workflow_service method must be implemented on the class that includes LyberCore::Robot'
|
57
33
|
end
|
58
34
|
|
59
35
|
# Sets up logging, timing and error handling of the job
|
60
36
|
# Calls the #perform method, then sets workflow to 'completed' or 'error' depending on success
|
61
37
|
def work(druid)
|
62
|
-
Honeybadger.context(druid: druid,
|
63
|
-
|
38
|
+
Honeybadger.context(druid: druid, process: process, workflow_name: workflow_name) if defined? Honeybadger
|
39
|
+
workflow = workflow(druid)
|
64
40
|
LyberCore::Log.set_logfile($stdout) # let process manager(bluepill) handle logging
|
65
41
|
LyberCore::Log.info "#{druid} processing"
|
66
|
-
return if
|
42
|
+
return if check_queued_status && !item_queued?(druid)
|
67
43
|
|
68
|
-
# this is the default note to pass back to workflow service,
|
44
|
+
# this is the default note to pass back to workflow service,
|
45
|
+
# but it can be overriden by a robot that uses the Lybercore::Robot::ReturnState
|
46
|
+
# object to return a status
|
69
47
|
note = Socket.gethostname
|
70
48
|
|
71
49
|
# update the workflow status to indicate that started
|
72
|
-
|
73
|
-
workflow_service.update_status(druid: druid, workflow: @workflow_name, process: @step_name, status: 'started', elapsed: 1.0, note: note)
|
50
|
+
workflow.start(note)
|
74
51
|
|
75
52
|
result = nil
|
76
53
|
elapsed = Benchmark.realtime do
|
@@ -87,25 +64,36 @@ module LyberCore
|
|
87
64
|
workflow_state = 'completed'
|
88
65
|
end
|
89
66
|
# update the workflow status from its current state to the state returned by perform (or 'completed' as the default)
|
90
|
-
|
67
|
+
workflow.complete(workflow_state, elapsed, note)
|
68
|
+
|
91
69
|
LyberCore::Log.info "Finished #{druid} in #{sprintf('%0.4f', elapsed)}s"
|
92
70
|
rescue StandardError => e
|
93
71
|
Honeybadger.notify(e) if defined? Honeybadger
|
94
72
|
begin
|
95
73
|
LyberCore::Log.error e.message + "\n" + e.backtrace.join("\n")
|
96
|
-
|
74
|
+
workflow.error(e.message, Socket.gethostname)
|
97
75
|
rescue StandardError => e
|
98
|
-
LyberCore::Log.error "Cannot set #{druid} to status='error'\n
|
76
|
+
LyberCore::Log.error "Cannot set #{druid} to status='error'\n#{e.message}\n#{e.backtrace.join("\n")}"
|
99
77
|
raise e # send exception to Resque failed queue
|
100
78
|
end
|
101
79
|
end
|
102
80
|
|
103
81
|
private
|
104
82
|
|
83
|
+
def workflow(druid)
|
84
|
+
Workflow.new(workflow_service: workflow_service,
|
85
|
+
druid: druid,
|
86
|
+
workflow_name: workflow_name,
|
87
|
+
process: process)
|
88
|
+
end
|
89
|
+
|
105
90
|
def item_queued?(druid)
|
106
|
-
status = workflow_service.workflow_status(druid: druid,
|
91
|
+
status = workflow_service.workflow_status(druid: druid,
|
92
|
+
workflow: workflow_name,
|
93
|
+
process: process)
|
107
94
|
return true if status =~ /queued/i
|
108
|
-
|
95
|
+
|
96
|
+
msg = "Item #{druid} is not queued for #{process} (#{workflow_name}), but has status of '#{status}'. Will skip processing"
|
109
97
|
Honeybadger.notify(msg) if defined? Honeybadger
|
110
98
|
LyberCore::Log.warn msg
|
111
99
|
false
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LyberCore
|
4
|
+
# This encapsulates the workflow operations that lyber-core does
|
5
|
+
class Workflow
|
6
|
+
def initialize(workflow_service:, druid:, workflow_name:, process:)
|
7
|
+
@workflow_service = workflow_service
|
8
|
+
@druid = druid
|
9
|
+
@workflow_name = workflow_name
|
10
|
+
@process = process
|
11
|
+
end
|
12
|
+
|
13
|
+
def start(note)
|
14
|
+
workflow_service.update_status(druid: druid,
|
15
|
+
workflow: workflow_name,
|
16
|
+
process: process,
|
17
|
+
status: 'started',
|
18
|
+
elapsed: 1.0,
|
19
|
+
note: note)
|
20
|
+
end
|
21
|
+
|
22
|
+
def complete(status, elapsed, note)
|
23
|
+
workflow_service.update_status(druid: druid,
|
24
|
+
workflow: workflow_name,
|
25
|
+
process: process,
|
26
|
+
status: status,
|
27
|
+
elapsed: elapsed,
|
28
|
+
note: note)
|
29
|
+
end
|
30
|
+
|
31
|
+
def error(error_msg, error_text)
|
32
|
+
workflow_service.update_error_status(druid: druid,
|
33
|
+
workflow: workflow_name,
|
34
|
+
process: process,
|
35
|
+
error_msg: error_msg,
|
36
|
+
error_text: error_text)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
attr_reader :workflow_service, :druid, :workflow_name, :process
|
42
|
+
end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lyber-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alpana Pande
|
@@ -16,56 +16,8 @@ authors:
|
|
16
16
|
autorequire:
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
|
-
date: 2020-02-
|
19
|
+
date: 2020-02-06 00:00:00.000000000 Z
|
20
20
|
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
22
|
-
name: activesupport
|
23
|
-
requirement: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: '0'
|
28
|
-
type: :runtime
|
29
|
-
prerelease: false
|
30
|
-
version_requirements: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - ">="
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '0'
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: dor-services
|
37
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - ">="
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: 7.0.0
|
42
|
-
- - "<"
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
version: '9'
|
45
|
-
type: :runtime
|
46
|
-
prerelease: false
|
47
|
-
version_requirements: !ruby/object:Gem::Requirement
|
48
|
-
requirements:
|
49
|
-
- - ">="
|
50
|
-
- !ruby/object:Gem::Version
|
51
|
-
version: 7.0.0
|
52
|
-
- - "<"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '9'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: dor-workflow-client
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '3.11'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '3.11'
|
69
21
|
- !ruby/object:Gem::Dependency
|
70
22
|
name: coveralls
|
71
23
|
requirement: !ruby/object:Gem::Requirement
|
@@ -180,6 +132,7 @@ files:
|
|
180
132
|
- lib/lyber_core/log.rb
|
181
133
|
- lib/lyber_core/return_state.rb
|
182
134
|
- lib/lyber_core/robot.rb
|
135
|
+
- lib/lyber_core/workflow.rb
|
183
136
|
- lib/tasks/rdoc.rake
|
184
137
|
homepage: http://github.com/sul-dlss/lyber-core
|
185
138
|
licenses:
|
@@ -200,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
153
|
- !ruby/object:Gem::Version
|
201
154
|
version: 1.3.6
|
202
155
|
requirements: []
|
203
|
-
rubygems_version: 3.
|
156
|
+
rubygems_version: 3.0.3
|
204
157
|
signing_key:
|
205
158
|
specification_version: 4
|
206
159
|
summary: Core services used by the SUL Digital Library
|