rest-ftp-daemon 0.103.1 → 0.104.5
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/bin/rest-ftp-daemon +16 -7
- data/lib/rest-ftp-daemon/api/dashboard.rb +1 -1
- data/lib/rest-ftp-daemon/api/status.rb +1 -0
- data/lib/rest-ftp-daemon/constants.rb +2 -2
- data/lib/rest-ftp-daemon/helpers.rb +16 -11
- data/lib/rest-ftp-daemon/job.rb +24 -20
- data/lib/rest-ftp-daemon/job_queue.rb +2 -1
- data/lib/rest-ftp-daemon/static/css/main.css +5 -4
- data/lib/rest-ftp-daemon/views/dashboard.haml +7 -7
- data/lib/rest-ftp-daemon/views/dashboard_counters.haml +1 -1
- data/lib/rest-ftp-daemon/views/dashboard_jobs.haml +23 -16
- data/lib/rest-ftp-daemon/views/dashboard_tokens.haml +2 -4
- data/lib/rest-ftp-daemon/views/dashboard_workers.haml +7 -7
- data/lib/rest-ftp-daemon/worker_pool.rb +54 -32
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f80c711efa90f45d67c8b2c7648b4a951b8da6b
|
4
|
+
data.tar.gz: 9dbda28ce22feaff2becdc4d0f211963569134f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bca8882c3ad0b481f7ce99e9588d6ceba5a6ab009b60f74bfbaea0bc40536e8789753527a3cfb89515bf53de4e8314c8b57bea65a8caafef38c3b116e867855
|
7
|
+
data.tar.gz: 3971446df3aa2b11007997dd9a78a094787c6ecf55e5f86102c1914c0eb48d72643ff9d3e1074a7a13fff39fa3ef70d76ccf2b8854c086d7d8ca484840438af9
|
data/bin/rest-ftp-daemon
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
# Try to load libs
|
3
|
+
# Try to load external libs
|
4
4
|
app_root = File.dirname(__FILE__) + '/../'
|
5
5
|
begin
|
6
6
|
require "thin"
|
@@ -10,14 +10,19 @@ begin
|
|
10
10
|
rescue LoadError
|
11
11
|
raise "EXITING: some of basic libs were not found: thin, optparse, socket, timeout"
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
|
+
# Load helpers and constants
|
15
|
+
[:constants, :helpers].each do |lib|
|
16
|
+
require File.expand_path("#{app_root}/lib/rest-ftp-daemon/#{lib.to_s}")
|
17
|
+
end
|
18
|
+
|
14
19
|
puts
|
15
20
|
#puts "--- #{APP_NAME} #{APP_VER}"
|
16
21
|
|
17
22
|
# Detect options from ARGV
|
18
23
|
options = {}
|
19
24
|
parser = OptionParser.new do |opts|
|
20
|
-
opts.banner = "Usage: #{File.basename $0} [options] start|stop
|
25
|
+
opts.banner = "Usage: #{File.basename $0} [options] start|stop"
|
21
26
|
opts.on("-c", "--config CONFIGFILE") { |config| APP_CONF = config }
|
22
27
|
opts.on("-e", "--environment ENV") { |env| APP_ENV = env }
|
23
28
|
opts.on("", "--dev") { APP_ENV = "development" }
|
@@ -34,7 +39,7 @@ end
|
|
34
39
|
begin
|
35
40
|
parser.order!(ARGV)
|
36
41
|
command = ARGV.shift
|
37
|
-
unless ["start", "stop"
|
42
|
+
unless ["start", "stop"].include? command
|
38
43
|
puts parser
|
39
44
|
exit 11
|
40
45
|
end
|
@@ -51,10 +56,14 @@ unless File.exists? APP_CONF
|
|
51
56
|
end
|
52
57
|
|
53
58
|
# Load helpers and config, and merge options from ARGV into settings
|
54
|
-
|
55
|
-
require File.expand_path("#{app_root}/lib/rest-ftp-daemon
|
59
|
+
begin
|
60
|
+
require File.expand_path("#{app_root}/lib/rest-ftp-daemon/config")
|
61
|
+
Settings.merge!(options)
|
62
|
+
rescue Psych::SyntaxError => e
|
63
|
+
puts "EXITING: config file syntax error: #{e.message}"
|
64
|
+
exit 16
|
56
65
|
end
|
57
|
-
|
66
|
+
|
58
67
|
|
59
68
|
# Display compiled configuration
|
60
69
|
puts "--- #{APP_NAME} #{APP_VER}"
|
@@ -17,6 +17,7 @@ module RestFtpDaemon
|
|
17
17
|
uptime: (Time.now - APP_STARTED).round(1),
|
18
18
|
counters: $queue.counters,
|
19
19
|
status: $queue.counts_by_status,
|
20
|
+
vars: $pool.worker_vars,
|
20
21
|
jobs_count: $queue.all_size,
|
21
22
|
jobs_queued: $queue.queued.collect(&:id),
|
22
23
|
jobs_popped: $queue.popped.collect(&:id),
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# Terrific constants
|
2
2
|
APP_NAME = "rest-ftp-daemon"
|
3
|
-
APP_VER = "0.
|
3
|
+
APP_VER = "0.104.5"
|
4
4
|
|
5
5
|
# Some global constants
|
6
6
|
IDENT_JOB_LEN = 4
|
7
7
|
IDENT_NOTIF_LEN = 4
|
8
8
|
IDENT_RANDOM_LEN = 8
|
9
9
|
IDENT_TEMPFILE_LEN = 8
|
10
|
-
DEFAULT_LOGS_PIPE_LEN =
|
10
|
+
DEFAULT_LOGS_PIPE_LEN = 12
|
11
11
|
DEFAULT_LOGS_ID_LEN = 8
|
12
12
|
|
13
13
|
# Some defaults
|
@@ -83,26 +83,31 @@ module RestFtpDaemon
|
|
83
83
|
when :file
|
84
84
|
'label-primary'
|
85
85
|
when :ftp
|
86
|
-
'label-danger'
|
87
|
-
when :ftps
|
88
|
-
'label-warning'
|
89
|
-
when :ftpes
|
90
86
|
'label-warning'
|
87
|
+
when :ftps, :ftpes
|
88
|
+
'label-success'
|
91
89
|
else
|
92
|
-
|
90
|
+
'label-default'
|
93
91
|
end
|
94
92
|
"<div class=\"transfer-method label #{klass}\">#{method.upcase}</div>"
|
95
93
|
end
|
96
94
|
|
97
95
|
# Dates and times: date with time generator
|
98
|
-
def self.datetime_full
|
99
|
-
return "-" if
|
100
|
-
return
|
96
|
+
def self.datetime_full datetime
|
97
|
+
return "-" if datetime.nil?
|
98
|
+
return datetime.to_datetime.strftime("%d.%m.%Y %H:%M")
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.datetime_short datetime
|
102
|
+
# return param.class
|
103
|
+
return "-" if datetime.nil?
|
104
|
+
return "?" unless datetime.respond_to? :to_date
|
105
|
+
return datetime.to_datetime.strftime("%H:%M") if datetime.to_date == Time.now.to_date
|
106
|
+
return datetime.to_datetime.strftime("%d/%m %H:%M")
|
101
107
|
end
|
102
108
|
|
103
|
-
def self.
|
104
|
-
|
105
|
-
return param.to_datetime.strftime("%d/%m %H:%M")
|
109
|
+
def self.hide_credentials_from_url url
|
110
|
+
url.sub(/([a-z]+:\/\/[^\/]+):[^\/]+\@/, '\1@' )
|
106
111
|
end
|
107
112
|
|
108
113
|
end
|
data/lib/rest-ftp-daemon/job.rb
CHANGED
@@ -78,9 +78,6 @@ module RestFtpDaemon
|
|
78
78
|
rescue RestFtpDaemon::JobMissingAttribute => exception
|
79
79
|
return oops "rftpd.started", exception, :missing_attribute
|
80
80
|
|
81
|
-
# rescue RestFtpDaemon::JobSourceNotFound => exception
|
82
|
-
# return oops "rftpd.started", exception, :job_source_not_found
|
83
|
-
|
84
81
|
rescue RestFtpDaemon::JobUnresolvedTokens => exception
|
85
82
|
return oops "rftpd.started", exception, :unresolved_tokens
|
86
83
|
|
@@ -97,7 +94,7 @@ module RestFtpDaemon
|
|
97
94
|
return oops "rftpd.started", exception, :assertion_failed
|
98
95
|
|
99
96
|
rescue RestFtpDaemon::RestFtpDaemonException => exception
|
100
|
-
return oops "rftpd.started", exception, :prepare_failed
|
97
|
+
return oops "rftpd.started", exception, :prepare_failed, true
|
101
98
|
|
102
99
|
rescue Exception => exception
|
103
100
|
return oops "rftpd.started", exception, :prepare_unhandled, true
|
@@ -134,7 +131,10 @@ module RestFtpDaemon
|
|
134
131
|
return oops "rftpd.ended", exception, :conn_openssl_error
|
135
132
|
|
136
133
|
rescue Net::FTPPermError => exception
|
137
|
-
return oops "rftpd.ended", exception, :
|
134
|
+
return oops "rftpd.ended", exception, :ftp_perm_error
|
135
|
+
|
136
|
+
rescue Net::FTPTempError => exception
|
137
|
+
return oops "rftpd.ended", exception, :ftp_temp_error
|
138
138
|
|
139
139
|
rescue Errno::EMFILE => exception
|
140
140
|
return oops "rftpd.ended", exception, :too_many_open_files
|
@@ -152,7 +152,7 @@ module RestFtpDaemon
|
|
152
152
|
return oops "rftpd.started", exception, :assertion_failed
|
153
153
|
|
154
154
|
rescue RestFtpDaemon::RestFtpDaemonException => exception
|
155
|
-
return oops "rftpd.ended", exception, :transfer_failed
|
155
|
+
return oops "rftpd.ended", exception, :transfer_failed, true
|
156
156
|
|
157
157
|
rescue Exception => exception
|
158
158
|
return oops "rftpd.ended", exception, :transfer_unhandled, true
|
@@ -192,7 +192,6 @@ module RestFtpDaemon
|
|
192
192
|
def set attribute, value
|
193
193
|
@mutex.synchronize do
|
194
194
|
@params || {}
|
195
|
-
# return unless @params.is_a? Enumerable
|
196
195
|
@updated_at = Time.now
|
197
196
|
@params[attribute] = value
|
198
197
|
end
|
@@ -271,7 +270,8 @@ module RestFtpDaemon
|
|
271
270
|
|
272
271
|
# Method assertions and init
|
273
272
|
@status = :checking_source
|
274
|
-
raise RestFtpDaemon::JobAssertionFailed unless @source_path
|
273
|
+
raise RestFtpDaemon::JobAssertionFailed, "transfer/1" unless @source_path
|
274
|
+
raise RestFtpDaemon::JobAssertionFailed, "transfer/2" unless @target_url
|
275
275
|
@transfer_sent = 0
|
276
276
|
set :source_processed, 0
|
277
277
|
|
@@ -337,7 +337,7 @@ module RestFtpDaemon
|
|
337
337
|
info "Job.oops si[#{signal_name}] er[#{error_name.to_s}] ex[#{exception.class}] #{exception.message}"
|
338
338
|
|
339
339
|
# Close ftp connexion if open
|
340
|
-
@ftp.close unless @ftp.welcome.nil?
|
340
|
+
@ftp.close unless @ftp.nil? || @ftp.welcome.nil?
|
341
341
|
|
342
342
|
# Update job's internal status
|
343
343
|
@status = :failed
|
@@ -379,7 +379,8 @@ module RestFtpDaemon
|
|
379
379
|
# Method assertions
|
380
380
|
info "Job.ftp_init asserts"
|
381
381
|
@status = :ftp_init
|
382
|
-
raise RestFtpDaemon::JobAssertionFailed if @target_method.nil?
|
382
|
+
raise RestFtpDaemon::JobAssertionFailed, "ftp_init/1" if @target_method.nil?
|
383
|
+
raise RestFtpDaemon::JobAssertionFailed, "ftp_init/2" if @target_url.nil?
|
383
384
|
|
384
385
|
info "Job.ftp_init target_method [#{@target_method}]"
|
385
386
|
case @target_method
|
@@ -403,23 +404,27 @@ module RestFtpDaemon
|
|
403
404
|
@status = :ftp_connect
|
404
405
|
host = @target_url.host
|
405
406
|
info "Job.ftp_connect [#{host}]"
|
406
|
-
raise RestFtpDaemon::JobAssertionFailed if @ftp.nil?
|
407
|
+
raise RestFtpDaemon::JobAssertionFailed, "ftp_connect/1" if @ftp.nil?
|
408
|
+
raise RestFtpDaemon::JobAssertionFailed, "ftp_connect/2" if @target_url.nil?
|
407
409
|
|
408
410
|
@ftp.connect(host)
|
409
411
|
end
|
410
412
|
|
411
413
|
def ftp_login
|
412
414
|
@status = :ftp_login
|
413
|
-
|
414
|
-
|
415
|
+
raise RestFtpDaemon::JobAssertionFailed, "ftp_login/1" if @ftp.nil?
|
416
|
+
|
417
|
+
# use "anonymous" if user is empty
|
418
|
+
login = @target_url.user || "anonymous"
|
419
|
+
info "Job.ftp_login [#{login}]"
|
415
420
|
|
416
|
-
@ftp.login
|
421
|
+
@ftp.login login, @target_url.password
|
417
422
|
end
|
418
423
|
|
419
424
|
def ftp_chdir_or_buildpath path
|
420
425
|
# Method assertions
|
421
426
|
info "Job.ftp_chdir [#{path}] mkdir: #{@mkdir}"
|
422
|
-
raise RestFtpDaemon::JobAssertionFailed if path.nil?
|
427
|
+
raise RestFtpDaemon::JobAssertionFailed, "ftp_chdir_or_buildpath/1" if path.nil?
|
423
428
|
@status = :ftp_chdir
|
424
429
|
|
425
430
|
# Extract directory from path
|
@@ -473,7 +478,8 @@ module RestFtpDaemon
|
|
473
478
|
|
474
479
|
# Method assertions
|
475
480
|
@status = :ftp_presence
|
476
|
-
raise RestFtpDaemon::JobAssertionFailed if @ftp.nil?
|
481
|
+
raise RestFtpDaemon::JobAssertionFailed, "ftp_presence/1" if @ftp.nil?
|
482
|
+
raise RestFtpDaemon::JobAssertionFailed, "ftp_presence/2" if @target_url.nil?
|
477
483
|
|
478
484
|
# Get file list, sometimes the response can be an empty value
|
479
485
|
results = @ftp.list(target_name) rescue nil
|
@@ -487,8 +493,8 @@ module RestFtpDaemon
|
|
487
493
|
def ftp_transfer source_match, target_name = nil
|
488
494
|
# Method assertions
|
489
495
|
info "Job.ftp_transfer source_match [#{source_match}]"
|
490
|
-
raise RestFtpDaemon::JobAssertionFailed if @ftp.nil?
|
491
|
-
raise RestFtpDaemon::JobAssertionFailed if source_match.nil?
|
496
|
+
raise RestFtpDaemon::JobAssertionFailed, "ftp_transfer/1" if @ftp.nil?
|
497
|
+
raise RestFtpDaemon::JobAssertionFailed, "ftp_transfer/2" if source_match.nil?
|
492
498
|
|
493
499
|
# Use source filename if target path provided none (typically with multiple sources)
|
494
500
|
target_name ||= Helpers.extract_filename source_match
|
@@ -552,8 +558,6 @@ module RestFtpDaemon
|
|
552
558
|
t0 = Time.now
|
553
559
|
|
554
560
|
# Notify if requested
|
555
|
-
@status = :uploaded
|
556
|
-
info "Job.ftp_transfer uploaded"
|
557
561
|
unless notify_after_sec.nil? || (notified_at + notify_after_sec > Time.now)
|
558
562
|
notif_status = {
|
559
563
|
progress: percent1,
|
@@ -168,7 +168,8 @@ module RestFtpDaemon
|
|
168
168
|
|
169
169
|
def ordered_popped
|
170
170
|
@mutex_counters.synchronize do
|
171
|
-
@popped.sort_by { |item| [item.updated_at] }
|
171
|
+
@popped.sort_by { |item| [ item.wid.to_s, item.updated_at] }
|
172
|
+
# @popped.sort_by { |item| [item.status.to_s, item.wid.to_s, item.updated_at, - item.id.to_i] }
|
172
173
|
end
|
173
174
|
end
|
174
175
|
|
@@ -3,11 +3,11 @@
|
|
3
3
|
}
|
4
4
|
|
5
5
|
.transfer-method {
|
6
|
-
width: 35px
|
6
|
+
/*width: 35px;*/
|
7
7
|
}
|
8
8
|
|
9
9
|
.worker-label {
|
10
|
-
width: 25px
|
10
|
+
/*width: 25px;*/
|
11
11
|
}
|
12
12
|
|
13
13
|
.nobr {
|
@@ -27,8 +27,9 @@ table tr td, .fixed {
|
|
27
27
|
}
|
28
28
|
|
29
29
|
.label {
|
30
|
-
font-size:
|
31
|
-
padding:
|
30
|
+
font-size: 1em;
|
31
|
+
padding: 3px 3px 1px 3px;
|
32
|
+
margin-bottom: 1px ;
|
32
33
|
font-weight: normal;
|
33
34
|
display: inline-block;
|
34
35
|
font-family: sans-serif;
|
@@ -10,7 +10,7 @@
|
|
10
10
|
%body
|
11
11
|
|
12
12
|
.navbar.navbar-default.navbar-fixed
|
13
|
-
.container
|
13
|
+
.container-fluid
|
14
14
|
|
15
15
|
.navbar-header
|
16
16
|
%h1
|
@@ -20,7 +20,7 @@
|
|
20
20
|
= "[#{Settings.namespace}]"
|
21
21
|
|
22
22
|
|
23
|
-
.container
|
23
|
+
.container-fluid
|
24
24
|
|
25
25
|
= render :dashboard_headers
|
26
26
|
|
@@ -43,22 +43,22 @@
|
|
43
43
|
%table.table.table-striped.table-hover.table-condensed
|
44
44
|
%tr
|
45
45
|
%th ID
|
46
|
-
%th P
|
47
|
-
%th W
|
48
46
|
%th label
|
49
47
|
%th source
|
48
|
+
%th <=>
|
50
49
|
%th target
|
51
|
-
%th
|
50
|
+
%th date
|
52
51
|
%th status
|
53
52
|
%th progress
|
54
53
|
%th error
|
55
54
|
%th.text-right size
|
56
|
-
%th.text-right
|
55
|
+
%th.text-right rate
|
56
|
+
%th
|
57
57
|
|
58
58
|
- if @only.nil? && !@jobs_queued.empty?
|
59
59
|
= render :dashboard_jobs, {jobs: @jobs_queued, counts: @counts}
|
60
60
|
%tr
|
61
|
-
%th{colspan:
|
61
|
+
%th{colspan: 12}
|
62
62
|
|
63
63
|
= render :dashboard_jobs, {jobs: @jobs_current, counts: @counts}
|
64
64
|
|
@@ -6,6 +6,7 @@
|
|
6
6
|
- source_processing = job.get(:source_processing)
|
7
7
|
- presented = present job, :with => RestFtpDaemon::API::Entities::JobPresenter, hide_params: true
|
8
8
|
- errmsg = job.get :error_message
|
9
|
+
- method = job.get(:target_method)
|
9
10
|
|
10
11
|
- if !job.error.nil?
|
11
12
|
- trclass = "danger"
|
@@ -13,30 +14,25 @@
|
|
13
14
|
- trclass = "info"
|
14
15
|
- elsif job.status == :finished
|
15
16
|
- trclass = "success"
|
17
|
+
- elsif job.status == :queued
|
18
|
+
- trclass = "active"
|
16
19
|
- else
|
17
20
|
- trclass = "warning"
|
18
21
|
|
19
22
|
%tr{class: trclass}
|
20
23
|
|
21
|
-
%td{title: presented.to_json}
|
22
|
-
|
23
|
-
%td
|
24
|
-
- unless job.priority.nil?
|
25
|
-
= job.priority
|
26
|
-
|
27
|
-
%td
|
28
|
-
- unless job.wid.nil?
|
29
|
-
.label.label-default.flag.worker-label= job.wid
|
24
|
+
%td{title: presented.to_json}
|
25
|
+
%b= job.id
|
30
26
|
|
31
27
|
%td= job.label
|
32
28
|
|
33
29
|
%td{title: job.get(:source_path)}
|
34
|
-
=# Helpers.job_method_label job.get(:source_method)
|
35
30
|
= Helpers.highlight_tokens job.source
|
36
31
|
|
32
|
+
%td
|
33
|
+
= Helpers.job_method_label method
|
34
|
+
|
37
35
|
%td{title: job.get(:target_url)}
|
38
|
-
= Helpers.job_method_label job.get(:target_method)
|
39
|
-
=# job.target
|
40
36
|
= Helpers.highlight_tokens job.target
|
41
37
|
|
42
38
|
%td
|
@@ -44,8 +40,14 @@
|
|
44
40
|
|
45
41
|
%td
|
46
42
|
= job.status
|
47
|
-
|
48
|
-
|
43
|
+
|
44
|
+
-# if (source_count > 1) && (source_processed < source_count)
|
45
|
+
- if (source_processed < source_count)
|
46
|
+
%small= " (#{source_processed}/#{source_count})"
|
47
|
+
|
48
|
+
- unless source_processing.nil?
|
49
|
+
%br
|
50
|
+
%b= " #{source_processing}"
|
49
51
|
|
50
52
|
%td
|
51
53
|
- unless progress.nil?
|
@@ -57,8 +59,6 @@
|
|
57
59
|
- unless job.error || job.status == :finished
|
58
60
|
- unless progress.nil?
|
59
61
|
= "#{progress}%"
|
60
|
-
- unless source_processing.nil?
|
61
|
-
%small= " (#{source_processing})"
|
62
62
|
- else
|
63
63
|
.error{title: errmsg}
|
64
64
|
= Helpers.text_or_empty(job.error)
|
@@ -71,3 +71,10 @@
|
|
71
71
|
- if (bitrate = job.get :transfer_bitrate)
|
72
72
|
= Helpers.format_bytes(bitrate, "bps")
|
73
73
|
|
74
|
+
%td
|
75
|
+
- unless job.priority.nil?
|
76
|
+
.label.label-info.flag.worker-label= job.priority
|
77
|
+
|
78
|
+
- unless job.wid.nil?
|
79
|
+
%br
|
80
|
+
.label.label-warning.flag.worker-label= job.wid
|
@@ -8,21 +8,21 @@
|
|
8
8
|
%th ID
|
9
9
|
%th status
|
10
10
|
%th job
|
11
|
-
%th.text-right
|
11
|
+
%th.text-right updated
|
12
12
|
|
13
|
-
- @
|
14
|
-
|
13
|
+
- @worker_vars.each do |wid, vars|
|
14
|
+
-# status = vars[:status]
|
15
15
|
- style = styles[status] || ""
|
16
16
|
|
17
|
-
- if
|
18
|
-
- no_news_for = (Time.now -
|
17
|
+
- if vars[:updted_at].is_a? Time
|
18
|
+
- no_news_for = (Time.now - vars[:updted_at]).round(0)
|
19
19
|
- else
|
20
20
|
- no_news_for = "?"
|
21
21
|
|
22
22
|
%tr{class: style.to_s}
|
23
23
|
%td= wid
|
24
|
-
%td=
|
25
|
-
%td=
|
24
|
+
%td= vars[:status]
|
25
|
+
%td= vars[:jobid]
|
26
26
|
%td.text-right
|
27
27
|
= no_news_for
|
28
28
|
s
|
@@ -12,84 +12,106 @@ module RestFtpDaemon
|
|
12
12
|
|
13
13
|
# Prepare status hash
|
14
14
|
@statuses = {}
|
15
|
+
@workers = {}
|
15
16
|
|
16
17
|
# Create worker threads
|
17
18
|
info "WorkerPool initializing with #{number_threads} workers"
|
18
19
|
@mutex = Mutex.new
|
19
20
|
@counter = 0
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
number_threads.times do
|
23
|
+
# Increment counter
|
24
|
+
@mutex.synchronize do
|
25
|
+
@counter +=1
|
26
|
+
end
|
27
|
+
name = "w#{@counter}"
|
28
|
+
|
29
|
+
th = Thread.new name do
|
30
|
+
|
31
|
+
# Set thread context
|
32
|
+
Thread.current[:name] = name
|
33
|
+
Thread.current[:vars] = {
|
34
|
+
started_at: Time.now,
|
35
|
+
}
|
36
|
+
|
37
|
+
# Start working
|
38
|
+
work
|
27
39
|
end
|
40
|
+
|
41
|
+
# Add this worker to the ThreadGroup
|
42
|
+
@workers[name] = th
|
28
43
|
end
|
29
44
|
|
30
45
|
end
|
31
46
|
|
32
|
-
def work
|
33
|
-
worker_status
|
47
|
+
def work
|
48
|
+
worker_status :starting
|
49
|
+
|
34
50
|
loop do
|
35
51
|
|
36
52
|
begin
|
37
|
-
info "
|
53
|
+
info "waiting for a job"
|
38
54
|
|
39
55
|
# Wait for a job to come into the queue
|
40
|
-
worker_status
|
56
|
+
worker_status :waiting
|
41
57
|
job = $queue.pop
|
42
58
|
|
43
59
|
# Do the job
|
44
|
-
info "
|
45
|
-
|
46
|
-
job.
|
60
|
+
info "processing [#{job.id}]"
|
61
|
+
|
62
|
+
worker_status :processing, job.id
|
63
|
+
job.wid = Thread.current[:name]
|
47
64
|
job.process
|
48
|
-
info "
|
49
|
-
|
50
|
-
worker_status
|
65
|
+
info "processed [#{job.id}]"
|
66
|
+
job.wid = nil
|
67
|
+
worker_status :done
|
51
68
|
|
52
69
|
# Increment total processed jobs count
|
53
70
|
$queue.counter_inc :jobs_processed
|
54
71
|
|
55
72
|
rescue Exception => ex
|
56
|
-
worker_status
|
73
|
+
worker_status :crashed
|
57
74
|
info "UNHANDLED EXCEPTION: #{ex.message}"
|
58
75
|
ex.backtrace.each do |line|
|
59
76
|
info line, 1
|
60
77
|
end
|
61
78
|
sleep 1
|
79
|
+
|
62
80
|
else
|
81
|
+
# Clean job status
|
82
|
+
worker_status :free
|
83
|
+
job.wid = nil
|
63
84
|
|
64
|
-
# Clean job status
|
65
|
-
worker_status wid, :ready
|
66
|
-
job.wid = nil
|
67
85
|
end
|
68
86
|
|
69
87
|
end
|
70
88
|
end
|
71
89
|
|
72
|
-
def
|
73
|
-
|
74
|
-
|
90
|
+
def worker_vars
|
91
|
+
vars = {}
|
92
|
+
|
93
|
+
@workers.each do |name, thread|
|
94
|
+
#currents[thread.id] = thread.current
|
95
|
+
vars[thread[:name]] = thread[:vars]
|
75
96
|
end
|
97
|
+
|
98
|
+
vars
|
76
99
|
end
|
77
100
|
|
78
101
|
protected
|
79
102
|
|
103
|
+
def ping
|
104
|
+
end
|
105
|
+
|
80
106
|
def info message
|
81
107
|
return if @logger.nil?
|
82
|
-
@logger.info_with_id message
|
108
|
+
@logger.info_with_id message, id: Thread.current[:name]
|
83
109
|
end
|
84
110
|
|
85
|
-
def worker_status
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
@statuses[wid][:jobid] = jobid
|
90
|
-
@statuses[wid][:active_at] = Time.now
|
91
|
-
end
|
92
|
-
|
111
|
+
def worker_status status, jobid = nil
|
112
|
+
Thread.current[:vars][:status] = status
|
113
|
+
Thread.current[:vars][:jobid] = jobid
|
114
|
+
Thread.current[:vars][:updted_at] = Time.now
|
93
115
|
end
|
94
116
|
|
95
117
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest-ftp-daemon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.104.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno MEDICI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|