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.
@@ -9,18 +9,12 @@
9
9
  - errmsg = job.get :error_message
10
10
  - method = job.get(:target_method)
11
11
 
12
- - if !job.error.nil?
13
- - trclass = "danger"
14
- - elsif job.status == JOB_STATUS_UPLOADING
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-info.flag.worker-label= job.priority
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 updated
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
- - @worker_vars.each do |wid, vars|
14
- -# status = vars[:status]
15
- - style = styles[status] || ""
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: style.to_s}
26
+ %tr{class: trclass.to_s}
23
27
  %td= wid
24
- %td= vars[:status]
25
- %td= vars[:jobid]
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 "A thread count of #{number_threads} is less than one" if number_threads < 1
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 worker_vars
29
- vars = {}
30
-
31
- @workers.each do |name, thread|
32
- #currents[thread.id] = thread.current
33
- vars[thread[:name]] = thread[:vars]
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
- vars
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
- name = "w#{@counter}"
50
- @workers[name] = create_worker_thread name
51
+ wid = "w#{@counter}"
52
+ @workers[wid] = create_worker_thread wid
51
53
  end
52
-
53
54
  end
54
- def create_worker_thread name
55
- @workers[name] = Thread.new name do
55
+
56
+ def create_worker_thread wid
57
+ Thread.new wid do
56
58
 
57
59
  # Set thread context
58
- Thread.current[:name] = name
59
- Thread.current[:vars] = { started_at: Time.now }
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
- work
63
- end
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
- worker_status :starting
69
-
70
- loop do
71
-
72
- begin
73
- info "waiting for a job"
74
-
75
- # Wait for a job to come into the queue
76
- worker_status :waiting
77
- job = $queue.pop
78
-
79
- # Do the job
80
- info "processing [#{job.id}]"
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
- def handle_job_uncaught_exception job, ex
106
- begin
107
- # Log the exception
108
- info "UNHDNALED EXCEPTION: job: #{ex.message}", lines: ex.backtrace
89
+ # Processing done
90
+ worker_status :done
91
+ info "job processed"
92
+ worker_jid nil
93
+ job.wid = nil
109
94
 
110
- # Tell the worker has creashed
111
- worker_status :crashed
95
+ # Increment total processed jobs count
96
+ $queue.counter_inc :jobs_processed
112
97
 
113
- # Flag the job as crashed
114
- job.oops_after_crash ex
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
- rescue Exception => ex
117
- info "DOUBLE EXCEPTION: #{ex.message}", lines: ex.backtrace
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
- end
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, context
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 worker_status status, jobid = nil
144
- Thread.current[:vars][:status] = status
145
- Thread.current[:vars][:jobid] = jobid
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
@@ -9,17 +9,18 @@ defaults: &defaults
9
9
 
10
10
  transfer:
11
11
  update_every_kb: 1024
12
- notify_after_sec: 10
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: 600
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-work.log"
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.202.2
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-19 00:00:00.000000000 Z
11
+ date: 2015-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler