rest-ftp-daemon 0.202.2 → 0.210.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -2
- data/lib/rest-ftp-daemon.rb +8 -1
- data/lib/rest-ftp-daemon/api/dashboard.rb +14 -4
- data/lib/rest-ftp-daemon/api/jobs.rb +6 -4
- data/lib/rest-ftp-daemon/api/root.rb +4 -9
- data/lib/rest-ftp-daemon/api/status.rb +3 -4
- data/lib/rest-ftp-daemon/constants.rb +41 -19
- data/lib/rest-ftp-daemon/exceptions.rb +1 -0
- data/lib/rest-ftp-daemon/helpers.rb +3 -5
- data/lib/rest-ftp-daemon/job.rb +110 -92
- data/lib/rest-ftp-daemon/job_queue.rb +88 -80
- data/lib/rest-ftp-daemon/logger.rb +5 -3
- data/lib/rest-ftp-daemon/logger_pool.rb +3 -2
- data/lib/rest-ftp-daemon/notification.rb +13 -18
- data/lib/rest-ftp-daemon/views/dashboard.haml +1 -1
- data/lib/rest-ftp-daemon/views/dashboard_jobs.haml +18 -6
- data/lib/rest-ftp-daemon/views/dashboard_table.haml +5 -11
- data/lib/rest-ftp-daemon/views/dashboard_workers.haml +14 -12
- data/lib/rest-ftp-daemon/worker_pool.rb +73 -83
- data/rest-ftp-daemon.yml.sample +6 -4
- metadata +2 -2
@@ -9,18 +9,12 @@
|
|
9
9
|
- errmsg = job.get :error_message
|
10
10
|
- method = job.get(:target_method)
|
11
11
|
|
12
|
-
-
|
13
|
-
|
14
|
-
-
|
15
|
-
- trclass = "info"
|
16
|
-
- elsif job.status == JOB_STATUS_FINISHED
|
17
|
-
- trclass = "success"
|
18
|
-
- elsif job.status == JOB_STATUS_QUEUED
|
19
|
-
- trclass = "active"
|
20
|
-
- else
|
12
|
+
- trclass = JOB_STYLES[job.status]
|
13
|
+
|
14
|
+
- unless job.error.nil?
|
21
15
|
- trclass = "warning"
|
22
16
|
|
23
|
-
%tr{class: trclass}
|
17
|
+
%tr{class: trclass.to_s}
|
24
18
|
|
25
19
|
%td{title: presented.to_json}
|
26
20
|
%b= job.id
|
@@ -78,7 +72,7 @@
|
|
78
72
|
|
79
73
|
%td
|
80
74
|
- unless job.priority.nil?
|
81
|
-
.label.label-
|
75
|
+
.label.label-default.flag.worker-label= job.priority
|
82
76
|
|
83
77
|
- unless job.wid.nil?
|
84
78
|
.label.label-warning.flag.worker-label= job.wid
|
@@ -1,5 +1,3 @@
|
|
1
|
-
- styles = {waiting: :success, processing: :info, crashed: :error, done: :success }
|
2
|
-
|
3
1
|
%h2 Workers
|
4
2
|
|
5
3
|
%table.table.table-striped.table-hover.table-condensed
|
@@ -8,22 +6,26 @@
|
|
8
6
|
%th ID
|
9
7
|
%th status
|
10
8
|
%th job
|
11
|
-
%th.text-right
|
9
|
+
%th.text-right seen
|
10
|
+
|
11
|
+
- @worker_variables.each do |vars|
|
12
|
+
- wid = vars[:wid]
|
13
|
+
- status = vars[:status]
|
14
|
+
- alive = $pool.worker_alive? wid
|
15
|
+
- trclass = WORKER_STYLES[status]
|
12
16
|
|
13
|
-
|
14
|
-
|
15
|
-
|
17
|
+
- unless alive
|
18
|
+
- trclass = "danger"
|
19
|
+
- status = "DEAD"
|
16
20
|
|
17
21
|
- if vars[:updted_at].is_a? Time
|
18
22
|
- no_news_for = (Time.now - vars[:updted_at]).round(0)
|
19
23
|
- else
|
20
24
|
- no_news_for = "?"
|
21
25
|
|
22
|
-
%tr{class:
|
26
|
+
%tr{class: trclass.to_s}
|
23
27
|
%td= wid
|
24
|
-
%td=
|
25
|
-
%td= vars[:
|
28
|
+
%td= status
|
29
|
+
%td= vars[:jid]
|
26
30
|
%td.text-right
|
27
|
-
= no_news_for
|
28
|
-
s
|
29
|
-
|
31
|
+
= "#{no_news_for} s"
|
@@ -1,5 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
module RestFtpDaemon
|
4
2
|
class WorkerPool
|
5
3
|
|
@@ -9,33 +7,37 @@ module RestFtpDaemon
|
|
9
7
|
# Logger
|
10
8
|
@logger = RestFtpDaemon::LoggerPool.instance.get :workers
|
11
9
|
|
12
|
-
|
13
10
|
# Check parameters
|
14
|
-
raise "
|
11
|
+
raise "at least one worker is needed to continue (#{number_threads} is less than one)" if number_threads < 1
|
15
12
|
|
16
13
|
# Prepare status hash and vars
|
17
14
|
@statuses = {}
|
18
15
|
@workers = {}
|
19
16
|
@mutex = Mutex.new
|
20
17
|
@counter = 0
|
18
|
+
@timeout = (Settings.transfer.timeout rescue nil) || DEFAULT_WORKER_TIMEOUT
|
21
19
|
|
22
20
|
# Create worker threads
|
23
|
-
info "WorkerPool initializing with #{number_threads} workers"
|
21
|
+
info "WorkerPool initializing with [#{number_threads}] workers and [#{@timeout}]s timeout"
|
24
22
|
create_worker_threads number_threads
|
25
23
|
|
26
24
|
end
|
27
25
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
def worker_variables
|
27
|
+
@workers.collect do |wid, worker|
|
28
|
+
vars = {}
|
29
|
+
worker.thread_variables.each do |var|
|
30
|
+
vars[var] = worker.thread_variable_get var
|
31
|
+
end
|
32
|
+
vars
|
34
33
|
end
|
34
|
+
end
|
35
35
|
|
36
|
-
|
36
|
+
def worker_alive? wid
|
37
|
+
@workers[wid] && @workers[wid].alive?
|
37
38
|
end
|
38
39
|
|
40
|
+
|
39
41
|
private
|
40
42
|
|
41
43
|
def create_worker_threads n
|
@@ -46,104 +48,92 @@ module RestFtpDaemon
|
|
46
48
|
end
|
47
49
|
|
48
50
|
# Create a dedicated thread for this worker
|
49
|
-
|
50
|
-
@workers[
|
51
|
+
wid = "w#{@counter}"
|
52
|
+
@workers[wid] = create_worker_thread wid
|
51
53
|
end
|
52
|
-
|
53
54
|
end
|
54
|
-
|
55
|
-
|
55
|
+
|
56
|
+
def create_worker_thread wid
|
57
|
+
Thread.new wid do
|
56
58
|
|
57
59
|
# Set thread context
|
58
|
-
Thread.current
|
59
|
-
Thread.current
|
60
|
+
Thread.current.thread_variable_set :wid, wid
|
61
|
+
Thread.current.thread_variable_set :started_at, Time.now
|
60
62
|
|
61
63
|
# Start working
|
62
|
-
|
63
|
-
|
64
|
+
worker_status :starting
|
65
|
+
loop do
|
66
|
+
work
|
67
|
+
end
|
64
68
|
|
69
|
+
end
|
65
70
|
end
|
66
71
|
|
67
72
|
def work
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
worker_status :processing, job.id
|
83
|
-
job.wid = Thread.current[:name]
|
84
|
-
job.process
|
85
|
-
info "processed [#{job.id}]"
|
86
|
-
job.wid = nil
|
87
|
-
worker_status :done
|
88
|
-
|
89
|
-
# Increment total processed jobs count
|
90
|
-
$queue.counter_inc :jobs_processed
|
91
|
-
|
92
|
-
rescue Exception => ex
|
93
|
-
handle_job_uncaught_exception job, ex
|
94
|
-
|
95
|
-
else
|
96
|
-
# Clean job status
|
97
|
-
worker_status :free
|
98
|
-
job.wid = nil
|
99
|
-
|
100
|
-
end
|
101
|
-
|
73
|
+
# Wait for a job to come into the queue
|
74
|
+
worker_status :waiting
|
75
|
+
info "waiting for a job"
|
76
|
+
job = $queue.pop
|
77
|
+
|
78
|
+
# Prepare the job for processing
|
79
|
+
worker_status :processing
|
80
|
+
info "job processing"
|
81
|
+
worker_jid job.id
|
82
|
+
job.wid = Thread.current.thread_variable_get :wid
|
83
|
+
|
84
|
+
# Processs this job protected by a timeout
|
85
|
+
status = Timeout::timeout(@timeout, RestFtpDaemon::JobTimeout) do
|
86
|
+
job.process
|
102
87
|
end
|
103
|
-
end
|
104
88
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
89
|
+
# Processing done
|
90
|
+
worker_status :done
|
91
|
+
info "job processed"
|
92
|
+
worker_jid nil
|
93
|
+
job.wid = nil
|
109
94
|
|
110
|
-
|
111
|
-
|
95
|
+
# Increment total processed jobs count
|
96
|
+
$queue.counter_inc :jobs_processed
|
112
97
|
|
113
|
-
|
114
|
-
|
98
|
+
rescue RestFtpDaemon::JobTimeout => ex
|
99
|
+
info "JOB TIMED OUT", lines: ex.backtrace
|
100
|
+
worker_status :timeout
|
101
|
+
job.oops_you_stop_now ex unless job.nil?
|
102
|
+
sleep 1
|
115
103
|
|
116
|
-
|
117
|
-
|
104
|
+
rescue Exception => ex
|
105
|
+
info "[#{job.id}] UNHDNALED EXCEPTION: #{ex.message}", lines: ex.backtrace
|
106
|
+
worker_status :crashed
|
107
|
+
job.oops_after_crash ex unless job.nil?
|
108
|
+
sleep 1
|
118
109
|
|
119
|
-
|
110
|
+
else
|
111
|
+
# Clean job status
|
112
|
+
worker_status :free
|
113
|
+
job.wid = nil
|
120
114
|
|
121
|
-
# Wait a bit
|
122
|
-
sleep 1
|
123
115
|
end
|
124
116
|
|
125
|
-
|
126
117
|
protected
|
127
118
|
|
128
|
-
def ping
|
129
|
-
end
|
130
|
-
|
131
119
|
def info message, context = {}
|
132
120
|
return if @logger.nil?
|
133
121
|
|
134
|
-
# Ensure context is a hash of options and inject context
|
135
|
-
context = {} unless context.is_a? Hash
|
136
|
-
context[:id] = Thread.current[:name]
|
137
|
-
context[:origin] = self.class
|
138
|
-
|
139
122
|
# Forward to logger
|
140
|
-
@logger.info_with_id message,
|
123
|
+
@logger.info_with_id message,
|
124
|
+
wid: Thread.current.thread_variable_get(:wid),
|
125
|
+
jid: Thread.current.thread_variable_get(:jid),
|
126
|
+
origin: self.class.to_s
|
127
|
+
end
|
128
|
+
|
129
|
+
def worker_status status
|
130
|
+
Thread.current.thread_variable_set :status, status
|
131
|
+
Thread.current.thread_variable_set :updted_at, Time.now
|
141
132
|
end
|
142
133
|
|
143
|
-
def
|
144
|
-
Thread.current
|
145
|
-
Thread.current
|
146
|
-
Thread.current[:vars][:updted_at] = Time.now
|
134
|
+
def worker_jid jid
|
135
|
+
Thread.current.thread_variable_set :jid, jid
|
136
|
+
Thread.current.thread_variable_set :updted_at, Time.now
|
147
137
|
end
|
148
138
|
|
149
139
|
end
|
data/rest-ftp-daemon.yml.sample
CHANGED
@@ -9,17 +9,18 @@ defaults: &defaults
|
|
9
9
|
|
10
10
|
transfer:
|
11
11
|
update_every_kb: 1024
|
12
|
-
notify_after_sec:
|
13
|
-
|
12
|
+
notify_after_sec: 5
|
14
13
|
mkdir: true
|
15
14
|
tempfile: true
|
16
15
|
overwrite: false
|
16
|
+
timeout: 1800
|
17
17
|
|
18
18
|
|
19
19
|
conchita:
|
20
20
|
timer: 10
|
21
21
|
#clean_failed: 3600
|
22
|
-
#clean_finished:
|
22
|
+
#clean_finished: 3600
|
23
|
+
#clean_queued: 86400
|
23
24
|
|
24
25
|
debug:
|
25
26
|
ftp: false
|
@@ -28,7 +29,8 @@ defaults: &defaults
|
|
28
29
|
thin: "/var/log/rftpd-environment-thin.log"
|
29
30
|
queue: "/var/log/rftpd-environment-core.log"
|
30
31
|
api: "/var/log/rftpd-environment-core.log"
|
31
|
-
workers: "/var/log/rftpd-environment-
|
32
|
+
workers: "/var/log/rftpd-environment-core.log"
|
33
|
+
jobs: "/var/log/rftpd-environment-work.log"
|
32
34
|
notify: "/var/log/rftpd-environment-work.log"
|
33
35
|
|
34
36
|
preprod:
|
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.210.0
|
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-03-
|
11
|
+
date: 2015-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|