cantemo-portal-agent 1.3.0 → 1.3.1
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b3f1ea75c5103dd91d6b863538cb5bd4b6ff7c2
|
4
|
+
data.tar.gz: '0796314e40e182e785a2d8cc8290be0e0a653545'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a57aeb7f14fceb67dfbbbfe091593c49ef57491fb5968b3f4b46e9a3beccff7964153a8b06d88e13268b10de315102db28a147647a5c9455090c4a7fe46af748
|
7
|
+
data.tar.gz: 68487f27150376d370b6254df75a339b49385d3957eb490e90e79bc9c3054dc7b77d8e5fe50dae5ad0ee42c9eea71d5fee803306e7378338c18bb6ae00e18083
|
@@ -37,12 +37,12 @@ op = OptionParser.new
|
|
37
37
|
op.on('-c', '--config-file-path FILEPATH', 'The path to the configuration file.',
|
38
38
|
"Default Path(s): #{args[:config_file_path]}") { |v| args[:config_file_path] = v }
|
39
39
|
# op.on('-b', '--[no-]background', 'Tells the application to run in the background.') { |v| args[:daemonize] = v }
|
40
|
-
op.on_tail('-t', '--log-to FILEPATH', 'Log file to log to') { |
|
41
|
-
op.on_tail('-l', '--log-level LEVEL',
|
42
|
-
args[:log_level] =
|
40
|
+
op.on_tail('-t', '--log-to FILEPATH', 'Log file to log to') { |v| args[:log_to] = v }
|
41
|
+
op.on_tail('-l', '--log-level LEVEL', %w(fatal error warn info debug), 'Select logging level') do |v|
|
42
|
+
args[:log_level] = v
|
43
43
|
end
|
44
44
|
op.on_tail('-v', '--version', 'Output the version and exit.') { puts "Version #{Cantemo::Portal::Agent::VERSION}"; exit }
|
45
|
-
op.on_tail('--help', 'Show this message.') { puts op; exit }
|
45
|
+
op.on_tail('-h', '--help', 'Show this message.') { puts op; exit }
|
46
46
|
op.load
|
47
47
|
op.parse!
|
48
48
|
|
@@ -53,27 +53,26 @@ if sub_command == 'help'
|
|
53
53
|
end
|
54
54
|
|
55
55
|
config_file_path = args[:config_file_path]
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
sub_command = sub_command.dup.downcase if sub_command
|
60
|
-
%w(start stop restart zap killall status).include?(sub_command)
|
61
|
-
end
|
62
|
-
should_daemonize = (daemon_control_command_present && %w(start restart).include?(sub_command)) || args[:daemonize]
|
63
|
-
|
64
|
-
if sub_command
|
65
|
-
case sub_command
|
66
|
-
when 'install'
|
67
|
-
puts
|
68
|
-
when 'uninstall'
|
69
|
-
puts
|
70
|
-
else
|
71
|
-
puts
|
72
|
-
end
|
56
|
+
if config_file_path.is_a?(Array)
|
57
|
+
args[:config_file_path].map! { |v| File.expand_path(v) }
|
58
|
+
config_file_path = config_file_path.find { |file_path| File.exist?(file_path) }
|
73
59
|
end
|
74
60
|
|
61
|
+
|
62
|
+
# daemon_control_command_present = sub_command && begin
|
63
|
+
# sub_command = sub_command.dup.downcase if sub_command
|
64
|
+
# %w(start stop restart zap killall status).include?(sub_command)
|
65
|
+
# end
|
66
|
+
# should_daemonize = (daemon_control_command_present && %w(start restart).include?(sub_command)) || args[:daemonize]
|
67
|
+
|
68
|
+
WATCH_FOLDER_MANAGER_CLASS = Envoi::Mam::Cantemo::Agent::WatchFolderManager
|
69
|
+
|
75
70
|
if sub_command == 'run'
|
76
|
-
|
71
|
+
begin
|
72
|
+
WATCH_FOLDER_MANAGER_CLASS.run(args)
|
73
|
+
rescue => e
|
74
|
+
abort("An exception occurred: #{e.message}#{args[:log_level] == 'debug' ? " - #{e.backtrace.first}" : ''}")
|
75
|
+
end
|
77
76
|
exit
|
78
77
|
end
|
79
78
|
|
@@ -110,16 +109,90 @@ module Application
|
|
110
109
|
end
|
111
110
|
|
112
111
|
def service_main(*args)
|
113
|
-
@WatchFolderManager =
|
112
|
+
@WatchFolderManager = WATCH_FOLDER_MANAGER_CLASS.run(args)
|
114
113
|
end
|
115
114
|
|
116
115
|
def service_stop
|
117
116
|
@WatchFolderManager.stop
|
118
117
|
end
|
119
118
|
|
119
|
+
def service_pause
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
def service_resume
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
# Watcher - Windows
|
120
128
|
end
|
121
129
|
else
|
122
|
-
class Watcher
|
130
|
+
class Watcher
|
131
|
+
APP_NAME = 'cantemo-portal-watch-folders'
|
132
|
+
|
133
|
+
def self.run(args)
|
134
|
+
WATCH_FOLDER_MANAGER_CLASS.run(args)
|
135
|
+
end
|
136
|
+
|
137
|
+
def self.daemons_run_proc_with_cleanup(options, &block)
|
138
|
+
options[:dir_mode] = :normal
|
139
|
+
options[:dir] = File.split(__FILE__)[0]
|
140
|
+
|
141
|
+
if block_given?
|
142
|
+
options[:mode] = :proc
|
143
|
+
options[:proc] = block
|
144
|
+
end
|
145
|
+
|
146
|
+
controller = Daemons::Controller.new(options, ARGV)
|
147
|
+
_command, _controller_part, _app_part = controller.class.split_argv(ARGV)
|
148
|
+
|
149
|
+
controller_group = Daemons::ApplicationGroup.new(controller.app_name, controller.options)
|
150
|
+
controller_group.controller_argv = _controller_part
|
151
|
+
controller_group.app_argv = _app_part
|
152
|
+
|
153
|
+
controller_group.setup
|
154
|
+
applications = controller_group.applications
|
155
|
+
|
156
|
+
is_running = applications.find { |a| a.running? }
|
157
|
+
if !applications.empty?
|
158
|
+
puts "Found #{applications.length} existing pid file(s) #{applications.map { |a| a.pid.pid }}"
|
159
|
+
should_zap_all = !is_running || (applications.length == 1 && applications.first.pid.pid == 0)
|
160
|
+
if should_zap_all
|
161
|
+
warn "Found stale pid file(s)"
|
162
|
+
controller_group.zap_all
|
163
|
+
controller_group.options[:force] = true
|
164
|
+
# controller_group.applications = []
|
165
|
+
|
166
|
+
controller.options[:force] = true
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
Daemons.run_proc(options[:app_name], options, &block)
|
171
|
+
# controller.catch_exceptions do
|
172
|
+
# controller.run
|
173
|
+
# end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
def self.run_with_process_manager(args, options = {})
|
178
|
+
# ARGV.unshift 'run' unless %w(start stop restart run zap killall status).include? ARGV.first
|
179
|
+
self.run(args)
|
180
|
+
require 'daemons'
|
181
|
+
proc = Proc.new { self.run(args) }
|
182
|
+
app_name = APP_NAME
|
183
|
+
|
184
|
+
# options[:app_name] = app_name
|
185
|
+
# daemons_run_proc_with_cleanup(options, &proc)
|
186
|
+
|
187
|
+
# options[:force] = true
|
188
|
+
Daemons.run_proc(app_name, options, &proc)
|
189
|
+
end
|
190
|
+
|
191
|
+
def self.run_in_foreground(args, options = { })
|
192
|
+
self.run(args)
|
193
|
+
end
|
194
|
+
# Watcher - *nix
|
195
|
+
end
|
123
196
|
end
|
124
197
|
|
125
198
|
|
@@ -139,18 +212,16 @@ end
|
|
139
212
|
|
140
213
|
if !Application::OS.windows?
|
141
214
|
begin
|
142
|
-
|
215
|
+
Application.run_with_process_manager(args)
|
143
216
|
exit
|
144
217
|
rescue => e
|
145
|
-
abort("An
|
218
|
+
abort("An exception occurred: #{e.message}#{args[:log_level] == 'debug' ? " - #{e.backtrace.first}" : ''}")
|
146
219
|
end
|
147
220
|
end
|
148
221
|
|
149
222
|
# Options:
|
150
|
-
# install - Installs the service.
|
151
|
-
#
|
152
|
-
# start - Starts the service. Make sure you stop it at some point or
|
153
|
-
# you will eventually fill up your filesystem!.
|
223
|
+
# install - Installs the service.
|
224
|
+
# start - Starts the service.
|
154
225
|
# stop - Stops the service.
|
155
226
|
# pause - Pauses the service.
|
156
227
|
# resume - Resumes the service.
|
@@ -161,31 +232,18 @@ require 'rbconfig'
|
|
161
232
|
include Win32
|
162
233
|
include RbConfig
|
163
234
|
|
164
|
-
# Make sure you're using the version you think you're using.
|
165
|
-
puts 'VERSION: ' + Service::VERSION
|
166
|
-
|
167
235
|
SERVICE_NAME = 'cantemo_portal_watch_folder_agent'
|
168
236
|
SERVICE_DISPLAYNAME = 'Cantemo Portal Watch Folder Agent'
|
169
237
|
EXECUTABLE_NAME = __FILE__
|
170
238
|
|
171
239
|
|
172
240
|
# You must provide at least one argument.
|
173
|
-
|
241
|
+
abort('No argument provided.') unless sub_command
|
242
|
+
abort('Service not installed.') unless Service.exists?(SERVICE_NAME) && sub_command == 'install'
|
174
243
|
|
175
|
-
case sub_command
|
176
|
-
when 'install'
|
177
|
-
# Quote the full path to deal with possible spaces in the path name.
|
178
|
-
ruby = File.join(CONFIG['bindir'], CONFIG['ruby_install_name']).tr('/', '\\')
|
179
|
-
path = %Q(#{File.dirname(File.expand_path($0)).tr('/', '\\')}\\#{EXECUTABLE_NAME})
|
180
|
-
cmd = %Q("#{ruby}" "#{path}" run --config-file-path "#{config_file_path}")
|
181
244
|
|
182
|
-
|
183
|
-
|
184
|
-
:display_name => SERVICE_DISPLAYNAME,
|
185
|
-
:description => 'Watch Folder Agent for Cantemo Portal',
|
186
|
-
:binary_path_name => cmd
|
187
|
-
)
|
188
|
-
puts 'Service ' + SERVICE_NAME + ' installed'
|
245
|
+
case sub_command
|
246
|
+
when 'runasservice'
|
189
247
|
when 'start'
|
190
248
|
if Service.status(SERVICE_NAME).current_state != 'running'
|
191
249
|
Service.start(SERVICE_NAME, nil)
|
@@ -208,16 +266,6 @@ when 'stop'
|
|
208
266
|
else
|
209
267
|
puts 'Already stopped'
|
210
268
|
end
|
211
|
-
when 'uninstall', 'delete'
|
212
|
-
if Service.status(SERVICE_NAME).current_state != 'stopped'
|
213
|
-
Service.stop(SERVICE_NAME)
|
214
|
-
end
|
215
|
-
while Service.status(SERVICE_NAME).current_state != 'stopped'
|
216
|
-
puts 'One moment...' + Service.status(SERVICE_NAME).current_state
|
217
|
-
sleep 1
|
218
|
-
end
|
219
|
-
Service.delete(SERVICE_NAME)
|
220
|
-
puts 'Service ' + SERVICE_NAME + ' deleted'
|
221
269
|
when 'pause'
|
222
270
|
if Service.status(SERVICE_NAME).current_state != 'paused'
|
223
271
|
Service.pause(SERVICE_NAME)
|
@@ -242,6 +290,30 @@ when 'resume'
|
|
242
290
|
end
|
243
291
|
when 'status'
|
244
292
|
puts Service.status(SERVICE_NAME)
|
293
|
+
when 'install'
|
294
|
+
# Quote the full path to deal with possible spaces in the path name.
|
295
|
+
ruby = File.join(CONFIG['bindir'], CONFIG['ruby_install_name']).tr('/', '\\')
|
296
|
+
path = %Q(#{File.dirname(File.expand_path($0)).tr('/', '\\')}\\#{EXECUTABLE_NAME})
|
297
|
+
cmd = %Q("#{ruby}" "#{path}" runasservice --config-file-path "#{config_file_path}")
|
298
|
+
|
299
|
+
Service.new(
|
300
|
+
:service_name => SERVICE_NAME,
|
301
|
+
:display_name => SERVICE_DISPLAYNAME,
|
302
|
+
:description => 'Watch Folder Agent for Cantemo Portal',
|
303
|
+
:binary_path_name => cmd
|
304
|
+
)
|
305
|
+
puts 'Service ' + SERVICE_NAME + ' installed'
|
306
|
+
when 'uninstall', 'delete'
|
307
|
+
if Service.status(SERVICE_NAME).current_state != 'stopped'
|
308
|
+
Service.stop(SERVICE_NAME)
|
309
|
+
end
|
310
|
+
while Service.status(SERVICE_NAME).current_state != 'stopped'
|
311
|
+
puts 'One moment...' + Service.status(SERVICE_NAME).current_state
|
312
|
+
sleep 1
|
313
|
+
end
|
314
|
+
Service.delete(SERVICE_NAME)
|
315
|
+
puts 'Service ' + SERVICE_NAME + ' deleted'
|
316
|
+
|
245
317
|
else
|
246
318
|
raise ArgumentError, 'unknown option: ' + sub_command
|
247
319
|
end
|
@@ -5,48 +5,10 @@ require 'envoi/watch_folder_utility/watch_folder/handler/listen'
|
|
5
5
|
|
6
6
|
module Envoi::Mam::Cantemo
|
7
7
|
|
8
|
-
module OS
|
9
|
-
def OS.windows?
|
10
|
-
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
|
11
|
-
end
|
12
|
-
|
13
|
-
def OS.mac?
|
14
|
-
(/darwin/ =~ RUBY_PLATFORM) != nil
|
15
|
-
end
|
16
|
-
|
17
|
-
def OS.unix?
|
18
|
-
!OS.windows?
|
19
|
-
end
|
20
|
-
|
21
|
-
def OS.linux?
|
22
|
-
OS.unix? and not OS.mac?
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
8
|
class Agent
|
27
9
|
|
28
10
|
class WatchFolderManager
|
29
11
|
|
30
|
-
|
31
|
-
class MultiIO
|
32
|
-
def initialize(*targets)
|
33
|
-
@targets = targets
|
34
|
-
end
|
35
|
-
|
36
|
-
def write(*args)
|
37
|
-
@targets.each {|t| t.write(*args)}
|
38
|
-
end
|
39
|
-
|
40
|
-
def close
|
41
|
-
@targets.each(&:close)
|
42
|
-
end
|
43
|
-
|
44
|
-
def add_target(*target)
|
45
|
-
@targets.concat target
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
12
|
class MultiLogger
|
51
13
|
attr_accessor :targets
|
52
14
|
|
@@ -340,6 +302,10 @@ module Envoi::Mam::Cantemo
|
|
340
302
|
end
|
341
303
|
end
|
342
304
|
|
305
|
+
def run_once
|
306
|
+
# AWF.run_once(watch_folders) { |wf| process_watch_folder(wf) }
|
307
|
+
end
|
308
|
+
|
343
309
|
# The main execution method
|
344
310
|
def run
|
345
311
|
@should_run = true
|
@@ -367,18 +333,28 @@ module Envoi::Mam::Cantemo
|
|
367
333
|
logger.info { 'Exiting...' }
|
368
334
|
end
|
369
335
|
|
370
|
-
def run_once
|
371
|
-
# AWF.run_once(watch_folders) { |wf| process_watch_folder(wf) }
|
372
|
-
end
|
373
|
-
|
374
336
|
def stop
|
375
337
|
if @should_run
|
376
338
|
@should_run = false
|
377
|
-
logger.info {
|
339
|
+
logger.info { 'Stopping...' }
|
378
340
|
watch_folders.each { |wf| wf.stop if wf.respond_to?(:stop) }
|
379
341
|
end
|
380
342
|
end
|
381
343
|
|
344
|
+
def pause
|
345
|
+
if @should_run
|
346
|
+
logger.info { 'Pausing...' }
|
347
|
+
watch_folders.each { |wf| wf.pause if wf.respond_to?(:pause) }
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
def resume
|
352
|
+
if @should_run
|
353
|
+
logger.info { 'Resuming...' }
|
354
|
+
watch_folders.each { |wf| wf.resume if wf.respond_to?(:resume) }
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
382
358
|
# Converts hash keys to symbols
|
383
359
|
#
|
384
360
|
# @param [Hash] value hash
|
@@ -398,67 +374,7 @@ module Envoi::Mam::Cantemo
|
|
398
374
|
def self.run(args)
|
399
375
|
w = self.new(args)
|
400
376
|
w.run
|
401
|
-
|
402
|
-
|
403
|
-
def self.daemons_run_proc_with_cleanup(options, &block)
|
404
|
-
options[:dir_mode] = :normal
|
405
|
-
options[:dir] = File.split(__FILE__)[0]
|
406
|
-
|
407
|
-
if block_given?
|
408
|
-
options[:mode] = :proc
|
409
|
-
options[:proc] = block
|
410
|
-
end
|
411
|
-
|
412
|
-
controller = Daemons::Controller.new(options, ARGV)
|
413
|
-
_command, _controller_part, _app_part = controller.class.split_argv(ARGV)
|
414
|
-
|
415
|
-
controller_group = Daemons::ApplicationGroup.new(controller.app_name, controller.options)
|
416
|
-
controller_group.controller_argv = _controller_part
|
417
|
-
controller_group.app_argv = _app_part
|
418
|
-
|
419
|
-
controller_group.setup
|
420
|
-
applications = controller_group.applications
|
421
|
-
|
422
|
-
is_running = applications.find { |a| a.running? }
|
423
|
-
if !applications.empty?
|
424
|
-
puts "Found #{applications.length} existing pid file(s) #{applications.map { |a| a.pid.pid }}"
|
425
|
-
should_zap_all = !is_running || (applications.length == 1 && applications.first.pid.pid == 0)
|
426
|
-
if should_zap_all
|
427
|
-
warn "Found stale pid file(s)"
|
428
|
-
controller_group.zap_all
|
429
|
-
controller_group.options[:force] = true
|
430
|
-
# controller_group.applications = []
|
431
|
-
|
432
|
-
controller.options[:force] = true
|
433
|
-
end
|
434
|
-
end
|
435
|
-
|
436
|
-
Daemons.run_proc(options[:app_name], options, &block)
|
437
|
-
# controller.catch_exceptions do
|
438
|
-
# controller.run
|
439
|
-
# end
|
440
|
-
|
441
|
-
end
|
442
|
-
|
443
|
-
def self.run_with_process_manager(args, options = {})
|
444
|
-
# ARGV.unshift 'run' unless %w(start stop restart run zap killall status).include? ARGV.first
|
445
|
-
if OS.windows?
|
446
|
-
self.run(args)
|
447
|
-
else
|
448
|
-
require 'daemons'
|
449
|
-
proc = Proc.new { self.run(args) }
|
450
|
-
app_name = 'cantemo-portal-watch-folders'
|
451
|
-
|
452
|
-
# options[:app_name] = app_name
|
453
|
-
# daemons_run_proc_with_cleanup(options, &proc)
|
454
|
-
|
455
|
-
# options[:force] = true
|
456
|
-
Daemons.run_proc(app_name, options, &proc)
|
457
|
-
end
|
458
|
-
end
|
459
|
-
|
460
|
-
def self.run_in_foreground(args, options = { })
|
461
|
-
self.run(args)
|
377
|
+
w
|
462
378
|
end
|
463
379
|
|
464
380
|
end
|
@@ -229,8 +229,8 @@ module Envoi
|
|
229
229
|
|
230
230
|
logger.debug { "Initializing parameter 'upload/import arguments'." }
|
231
231
|
upload_args = watch_folder_def['upload_args']
|
232
|
-
item_add_args = watch_folder_def['item_add_args']
|
233
|
-
item_add_options = watch_folder_def['item_add_options']
|
232
|
+
item_add_args = watch_folder_def['item_add_args'] || { }
|
233
|
+
item_add_options = watch_folder_def['item_add_options'] || { }
|
234
234
|
import_args = watch_folder_def['import_args'] || { }
|
235
235
|
import_options = watch_folder_def['import_options'] || { }
|
236
236
|
|
@@ -238,26 +238,26 @@ module Envoi
|
|
238
238
|
import_options = Hash[import_options.map { |k,v| [ k.respond_to?(:to_sym) ? k.to_sym.downcase : k, v ] }]
|
239
239
|
|
240
240
|
# Allow adding to collection to be overridden
|
241
|
-
add_item_to_collection =
|
242
|
-
|
241
|
+
add_item_to_collection = item_add_args.fetch(:add_item_to_collection,
|
242
|
+
item_add_options.fetch(:add_item_to_collection,
|
243
243
|
watch_folder_def['add_item_to_collection']))
|
244
244
|
if add_item_to_collection.nil? || add_item_to_collection
|
245
245
|
_add_item_to_collection = false
|
246
246
|
collection_id = watch_folder_def['collection_id']
|
247
247
|
if collection_id
|
248
|
-
|
248
|
+
item_add_args[:collection_id] ||= collection_id
|
249
249
|
_add_item_to_collection = true
|
250
250
|
watch_folder_def.delete('collection_id')
|
251
251
|
else
|
252
252
|
collection_name = watch_folder_def['collection_name']
|
253
253
|
if collection_name
|
254
|
-
|
254
|
+
item_add_args[:collection_name] ||= collection_name
|
255
255
|
_add_item_to_collection = true
|
256
256
|
watch_folder_def.delete('collection_name')
|
257
257
|
else
|
258
258
|
file_path_collection_name_position = watch_folder_def['file_path_collection_name_position']
|
259
259
|
if file_path_collection_name_position
|
260
|
-
|
260
|
+
item_add_args[:file_path_collection_name_position] = file_path_collection_name_position
|
261
261
|
_add_item_to_collection = true
|
262
262
|
watch_folder_def.delete('file_path_collection_name_position')
|
263
263
|
end
|
@@ -268,13 +268,14 @@ module Envoi
|
|
268
268
|
|
269
269
|
metadata = watch_folder_def['metadata']
|
270
270
|
if metadata
|
271
|
-
|
271
|
+
item_add_args[:metadata] = metadata
|
272
272
|
watch_folder_def.delete('metadata')
|
273
273
|
end
|
274
274
|
|
275
|
-
|
276
|
-
if
|
277
|
-
|
275
|
+
field_group = watch_folder_def['field_group']
|
276
|
+
if field_group
|
277
|
+
item_add_args[:field_group] = field_group
|
278
|
+
watch_folder_def.delete('field_group')
|
278
279
|
end
|
279
280
|
|
280
281
|
ingest_group = watch_folder_def['ingest_group']
|
@@ -283,11 +284,12 @@ module Envoi
|
|
283
284
|
job_metadata += ',' unless job_metadata.empty?
|
284
285
|
job_metadata += "portal_groups:StringArray=#{ingest_group}"
|
285
286
|
import_args[:jobmetadata] = job_metadata
|
287
|
+
watch_folder_def.delete('ingest_group')
|
286
288
|
end
|
287
289
|
|
288
290
|
item_add_args = symbolize_keys(item_add_args)
|
289
|
-
(
|
290
|
-
(
|
291
|
+
(item_add_args[:import_args] ||= {}).merge! import_args if import_args.is_a?(Hash)
|
292
|
+
(item_add_args[:import_options] ||= {}).merge! import_options if import_options.is_a?(Hash)
|
291
293
|
|
292
294
|
upload_args = symbolize_keys(upload_args)
|
293
295
|
((upload_args ||= {})[:item_add_args] ||= {}).merge! item_add_args if item_add_args.is_a?(Hash)
|
@@ -398,8 +400,67 @@ module Envoi
|
|
398
400
|
end
|
399
401
|
end
|
400
402
|
|
401
|
-
|
403
|
+
# @param [Object] file
|
404
|
+
# @return [Hash]
|
405
|
+
def process_file(file)
|
406
|
+
file.processing = true
|
407
|
+
file_name = file.name || file.path
|
408
|
+
logger.debug { "Processing File '#{file_name}'" }
|
402
409
|
|
410
|
+
storage_id = watch_folder.definition['upload_to_storage_id']
|
411
|
+
|
412
|
+
unless storage_id
|
413
|
+
logger.warn { "Skipping processing of file because of missing storage ID." }
|
414
|
+
return { success: false, message: 'Missing storage ID.' }
|
415
|
+
end
|
416
|
+
|
417
|
+
quarantine_directory_path = definition['quarantine_directory_path']
|
418
|
+
completed_directory_path = definition['completed_directory_path']
|
419
|
+
watch_folder_upload_args = definition['upload_args']
|
420
|
+
|
421
|
+
# full_file_path = File.join(watch_folder.path, file.path)
|
422
|
+
full_file_path = file.path
|
423
|
+
|
424
|
+
upload_args = {
|
425
|
+
file_path: full_file_path,
|
426
|
+
storage_id: storage_id
|
427
|
+
}
|
428
|
+
upload_args.merge!(watch_folder_upload_args) if watch_folder_upload_args.is_a?(Hash)
|
429
|
+
|
430
|
+
logger.debug { "Executing Upload. #{upload_args}" }
|
431
|
+
_response = agent.upload(upload_args)
|
432
|
+
_response = { success: _response } if _response == true || _response == false
|
433
|
+
|
434
|
+
if _response[:success]
|
435
|
+
if completed_directory_path
|
436
|
+
if Dir.exist?(completed_directory_path)
|
437
|
+
logger.debug { "Moving '#{full_file_path}' to completed directory path '#{completed_directory_path}'" }
|
438
|
+
FileUtils.mv full_file_path, completed_directory_path
|
439
|
+
else
|
440
|
+
logger.warn { "Completed directory path not found: '#{completed_directory_path}'" }
|
441
|
+
add_to_ignore(file)
|
442
|
+
end
|
443
|
+
else
|
444
|
+
FileUtils.rm full_file_path
|
445
|
+
end
|
446
|
+
else
|
447
|
+
if quarantine_directory_path && Dir.exist?(quarantine_directory_path)
|
448
|
+
logger.warn { "Moving '#{full_file_path}' to quarantine directory path '#{quarantine_directory_path}'" }
|
449
|
+
FileUtils.mv full_file_path, quarantine_directory_path
|
450
|
+
else
|
451
|
+
logger.warn { "Adding '#{full_file_path}' to the temporary ignore list." }
|
452
|
+
add_to_ignore(file)
|
453
|
+
end
|
454
|
+
end
|
455
|
+
|
456
|
+
file.processed = true
|
457
|
+
|
458
|
+
_response
|
459
|
+
rescue => e
|
460
|
+
file.exception = e
|
461
|
+
raise e
|
462
|
+
ensure
|
463
|
+
file.processing = false
|
403
464
|
end
|
404
465
|
|
405
466
|
# Converts hash keys to symbols
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cantemo-portal-agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Whitson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asperalm
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 1.6.
|
75
|
+
version: 1.6.4
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 1.6.
|
82
|
+
version: 1.6.4
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: bundler
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|