rest-ftp-daemon 0.221.2 → 0.222.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/.rspec +2 -0
- data/.rubocop.yml +859 -0
- data/Gemfile.lock +34 -3
- data/README.md +6 -1
- data/Rakefile +8 -1
- data/bin/rest-ftp-daemon +9 -9
- data/config.ru +3 -3
- data/lib/rest-ftp-daemon.rb +43 -43
- data/lib/rest-ftp-daemon/api/dashboard.rb +14 -4
- data/lib/rest-ftp-daemon/api/job_presenter.rb +1 -1
- data/lib/rest-ftp-daemon/api/jobs.rb +42 -42
- data/lib/rest-ftp-daemon/api/root.rb +37 -17
- data/lib/rest-ftp-daemon/constants.rb +8 -8
- data/lib/rest-ftp-daemon/helpers.rb +12 -13
- data/lib/rest-ftp-daemon/job.rb +24 -23
- data/lib/rest-ftp-daemon/job_queue.rb +8 -9
- data/lib/rest-ftp-daemon/logger.rb +2 -14
- data/lib/rest-ftp-daemon/logger_pool.rb +1 -1
- data/lib/rest-ftp-daemon/notification.rb +5 -5
- data/lib/rest-ftp-daemon/paginate.rb +4 -3
- data/lib/rest-ftp-daemon/settings.rb +11 -11
- data/lib/rest-ftp-daemon/uri.rb +2 -2
- data/lib/rest-ftp-daemon/views/dashboard_table.haml +1 -1
- data/lib/rest-ftp-daemon/worker.rb +1 -1
- data/lib/rest-ftp-daemon/worker_conchita.rb +3 -3
- data/lib/rest-ftp-daemon/worker_job.rb +3 -3
- data/lib/rest-ftp-daemon/worker_pool.rb +6 -9
- data/rest-ftp-daemon.gemspec +3 -1
- data/rest-ftp-daemon.yml.sample +12 -11
- data/spec/rest-ftp-daemon/features/dashboard_spec.rb +23 -0
- data/spec/spec_helper.rb +62 -0
- data/spec/support/config.yml +26 -0
- metadata +35 -4
- data/lib/rest-ftp-daemon/api/debug.rb +0 -31
- data/lib/rest-ftp-daemon/api/status.rb +0 -33
@@ -47,12 +47,13 @@ module RestFtpDaemon
|
|
47
47
|
private
|
48
48
|
|
49
49
|
def link p
|
50
|
-
klass = (p == @page)?
|
51
|
-
|
50
|
+
klass = (p == @page)? " btn-info" : ""
|
51
|
+
|
52
|
+
"<a class='page btn btn-default%s' href='?only=%s&page=%d'>%p</a>" % [
|
52
53
|
klass,
|
53
54
|
@only,
|
54
55
|
p,
|
55
|
-
p
|
56
|
+
p
|
56
57
|
]
|
57
58
|
end
|
58
59
|
|
@@ -7,21 +7,22 @@ class Settings < Settingslogic
|
|
7
7
|
|
8
8
|
# Compute my PID filename
|
9
9
|
def pidfile
|
10
|
-
|
10
|
+
port = self["port"]
|
11
|
+
self["pidfile"] || "/tmp/#{APP_NAME}.port#{port}.pid"
|
11
12
|
end
|
12
13
|
|
13
14
|
# Direct access to any depth
|
14
15
|
def at *path
|
15
|
-
path.reduce(Settings) {|m,key| m && m[key.to_s] }
|
16
|
+
path.reduce(Settings) { |m, key| m && m[key.to_s] }
|
16
17
|
end
|
17
18
|
|
18
19
|
# Dump whole settings set to readable YAML
|
19
20
|
def dump
|
20
|
-
|
21
|
+
to_hash.to_yaml(indent: 4, useheader: true, useversion: false )
|
21
22
|
end
|
22
23
|
|
23
24
|
def init_defaults
|
24
|
-
Settings[
|
25
|
+
Settings["host"] ||= `hostname`.chomp.split(".").first
|
25
26
|
end
|
26
27
|
|
27
28
|
def newrelic_enabled?
|
@@ -30,21 +31,20 @@ class Settings < Settingslogic
|
|
30
31
|
|
31
32
|
def init_newrelic
|
32
33
|
# Skip if not enabled
|
33
|
-
return ENV[
|
34
|
+
return ENV["NEWRELIC_AGENT_ENABLED"] = "false" unless Settings.newrelic_enabled?
|
34
35
|
|
35
36
|
# Enable module
|
36
|
-
ENV[
|
37
|
-
ENV[
|
38
|
-
#Settings['newrelic']['enabled'] = true
|
37
|
+
ENV["NEWRELIC_AGENT_ENABLED"] = "true"
|
38
|
+
ENV["NEW_RELIC_MONITOR_MODE"] = "true"
|
39
39
|
|
40
40
|
# License
|
41
|
-
ENV[
|
41
|
+
ENV["NEW_RELIC_LICENSE_KEY"] = Settings.at(:debug, :newrelic)
|
42
42
|
|
43
43
|
# Appname
|
44
|
-
ENV[
|
44
|
+
ENV["NEW_RELIC_APP_NAME"] = "#{APP_NICK}-#{Settings.host}-#{APP_ENV}"
|
45
45
|
|
46
46
|
# Logfile
|
47
|
-
ENV[
|
47
|
+
ENV["NEW_RELIC_LOG"] = Settings.at(:logs, :newrelic)
|
48
48
|
end
|
49
49
|
|
50
50
|
end
|
data/lib/rest-ftp-daemon/uri.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
- source_count = job.get(:source_count) || 0
|
4
4
|
- source_processed = job.get(:source_processed) || 0
|
5
5
|
- source_current = job.get(:source_current)
|
6
|
-
- presented = present job, :
|
6
|
+
- presented = present job, with: RestFtpDaemon::API::Entities::JobPresenter, hide_params: true
|
7
7
|
- bitrate = job.get :transfer_bitrate
|
8
8
|
|
9
9
|
- trclass = JOB_STYLES[job.status]
|
@@ -32,7 +32,7 @@ module RestFtpDaemon
|
|
32
32
|
worker_status :collecting
|
33
33
|
GC.start if @conchita["garbage_collector"]
|
34
34
|
|
35
|
-
rescue
|
35
|
+
rescue StandardError => e
|
36
36
|
log_error "EXCEPTION: #{e.inspect}"
|
37
37
|
sleep 1
|
38
38
|
else
|
@@ -42,12 +42,12 @@ module RestFtpDaemon
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def maxage status
|
45
|
-
@conchita["clean_#{status
|
45
|
+
@conchita["clean_#{status}"] || 0
|
46
46
|
end
|
47
47
|
|
48
48
|
|
49
49
|
if Settings.newrelic_enabled?
|
50
|
-
add_transaction_tracer :work,
|
50
|
+
add_transaction_tracer :work, category: :task
|
51
51
|
end
|
52
52
|
|
53
53
|
end
|
@@ -28,7 +28,7 @@ module RestFtpDaemon
|
|
28
28
|
job.wid = Thread.current.thread_variable_get :wid
|
29
29
|
|
30
30
|
# Processs this job protected by a timeout
|
31
|
-
Timeout
|
31
|
+
Timeout.timeout(@timeout, RestFtpDaemon::JobTimeout) do
|
32
32
|
job.process
|
33
33
|
end
|
34
34
|
|
@@ -50,7 +50,7 @@ module RestFtpDaemon
|
|
50
50
|
job.oops_you_stop_now ex unless job.nil?
|
51
51
|
sleep 1
|
52
52
|
|
53
|
-
rescue
|
53
|
+
rescue StandardError => ex
|
54
54
|
log_error "JOB UNHDNALED EXCEPTION: #{ex.message}", lines: ex.backtrace
|
55
55
|
worker_status :crashed
|
56
56
|
job.oops_after_crash ex unless job.nil?
|
@@ -65,7 +65,7 @@ module RestFtpDaemon
|
|
65
65
|
|
66
66
|
|
67
67
|
if Settings.newrelic_enabled?
|
68
|
-
add_transaction_tracer :work,
|
68
|
+
add_transaction_tracer :work, category: :task
|
69
69
|
end
|
70
70
|
|
71
71
|
end
|
@@ -12,9 +12,6 @@ module RestFtpDaemon
|
|
12
12
|
def initialize
|
13
13
|
# Logger
|
14
14
|
@logger = RestFtpDaemon::LoggerPool.instance.get :workers
|
15
|
-
# log_info "WorkerPool: log_info"
|
16
|
-
# log_error "WorkerPool: log_error"
|
17
|
-
# log_error "WorkerPool: log_error + lines", ['line1', 'line2']
|
18
15
|
|
19
16
|
# Prepare status hash and vars
|
20
17
|
@statuses = {}
|
@@ -30,7 +27,7 @@ module RestFtpDaemon
|
|
30
27
|
end
|
31
28
|
|
32
29
|
def worker_variables
|
33
|
-
@workers.collect do |
|
30
|
+
@workers.collect do |_wid, worker|
|
34
31
|
vars = {}
|
35
32
|
worker.thread_variables.each do |var|
|
36
33
|
vars[var] = worker.thread_variable_get var
|
@@ -73,7 +70,7 @@ module RestFtpDaemon
|
|
73
70
|
# Start conchita thread
|
74
71
|
@conchita = create_conchita_thread
|
75
72
|
|
76
|
-
rescue
|
73
|
+
rescue StandardError => ex
|
77
74
|
log_error "UNHDNALED EXCEPTION: #{ex.message}", ex.backtrace
|
78
75
|
|
79
76
|
end
|
@@ -83,7 +80,7 @@ module RestFtpDaemon
|
|
83
80
|
begin
|
84
81
|
worker = JobWorker.new wid
|
85
82
|
log_info "JobWorker [#{wid}]: #{worker}"
|
86
|
-
rescue
|
83
|
+
rescue StandardError => ex
|
87
84
|
log_error "EXCEPTION: #{ex.message}"
|
88
85
|
end
|
89
86
|
end
|
@@ -94,7 +91,7 @@ module RestFtpDaemon
|
|
94
91
|
begin
|
95
92
|
worker = ConchitaWorker.new :conchita
|
96
93
|
log_info "ConchitaWorker: #{worker}"
|
97
|
-
rescue
|
94
|
+
rescue StandardError => ex
|
98
95
|
log_error "EXCEPTION: #{ex.message}"
|
99
96
|
end
|
100
97
|
end
|
@@ -103,8 +100,8 @@ module RestFtpDaemon
|
|
103
100
|
protected
|
104
101
|
|
105
102
|
if Settings.newrelic_enabled?
|
106
|
-
add_transaction_tracer :create_conchita_thread,
|
107
|
-
add_transaction_tracer :create_worker_thread,
|
103
|
+
add_transaction_tracer :create_conchita_thread, category: :task
|
104
|
+
add_transaction_tracer :create_worker_thread, category: :task
|
108
105
|
end
|
109
106
|
|
110
107
|
end
|
data/rest-ftp-daemon.gemspec
CHANGED
@@ -22,10 +22,12 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.version = APP_VER
|
23
23
|
|
24
24
|
#spec.required_ruby_version = '>= 1.9.3'
|
25
|
-
spec.required_ruby_version =
|
25
|
+
spec.required_ruby_version = ">= 2.1"
|
26
26
|
|
27
27
|
spec.add_development_dependency "bundler", "~> 1.6"
|
28
28
|
spec.add_development_dependency "rake"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.1"
|
30
|
+
spec.add_development_dependency "http", "~> 0.8"
|
29
31
|
|
30
32
|
spec.add_runtime_dependency "thin", "~> 1.6"
|
31
33
|
spec.add_runtime_dependency "grape"
|
data/rest-ftp-daemon.yml.sample
CHANGED
@@ -2,21 +2,20 @@ defaults: &defaults
|
|
2
2
|
daemonize: true
|
3
3
|
port: 3000
|
4
4
|
workers: 2
|
5
|
-
#adminpwd: "admin"
|
6
5
|
user: rftpd
|
7
6
|
group: rftpd
|
8
|
-
host:
|
7
|
+
host: "myhost"
|
9
8
|
|
10
9
|
transfer:
|
11
|
-
update_every_kb: 1024
|
12
|
-
notify_after_sec: 5
|
13
|
-
mkdir: true
|
14
|
-
tempfile: true
|
15
|
-
overwrite: false
|
16
|
-
timeout: 1800
|
10
|
+
update_every_kb: 1024 # block size to transfer between counter updates
|
11
|
+
notify_after_sec: 5 # wait at least X seconds between HTTP notifications
|
12
|
+
mkdir: true # build directory tree if missing
|
13
|
+
tempfile: true # transfer to temporary file, rename after sucessful transfer
|
14
|
+
overwrite: false # overwrite any target file with the same name
|
15
|
+
timeout: 1800 # jobs running for longer than X seconds will be killed
|
17
16
|
|
18
17
|
conchita:
|
19
|
-
timer: 60
|
18
|
+
# timer: 60
|
20
19
|
# garbage_collector: true
|
21
20
|
# clean_failed: 3600
|
22
21
|
# clean_finished: 3600
|
@@ -24,7 +23,7 @@ defaults: &defaults
|
|
24
23
|
|
25
24
|
debug:
|
26
25
|
ftp: false
|
27
|
-
#
|
26
|
+
# newrelic: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
28
27
|
|
29
28
|
logs:
|
30
29
|
thin: "/var/log/rftpd-environment-thin.log"
|
@@ -35,8 +34,10 @@ defaults: &defaults
|
|
35
34
|
notify: "/var/log/rftpd-environment-work.log"
|
36
35
|
newrelic:"/var/log/rftpd-environment-newrelic.log"
|
37
36
|
|
38
|
-
|
37
|
+
|
38
|
+
development:
|
39
39
|
<<: *defaults
|
40
|
+
port: 3400
|
40
41
|
|
41
42
|
production:
|
42
43
|
<<: *defaults
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe 'Dashboard', feature: true do
|
4
|
+
|
5
|
+
describe "GET /" do
|
6
|
+
context 'without a password' do
|
7
|
+
it 'is forbidden' do
|
8
|
+
expect(HTTP.accept(:json).get("http://localhost:5678").status).to eq 401
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with a password' do
|
13
|
+
it 'can be accessed' do
|
14
|
+
expect(
|
15
|
+
HTTP.accept(:json).
|
16
|
+
basic_auth(user: 'admin', pass: 'admin').
|
17
|
+
get("http://localhost:5678").status
|
18
|
+
).to eq 200
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end # GET /
|
22
|
+
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require "pathname"
|
2
|
+
require "http"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# rspec-expectations config goes here. You can use an alternate
|
6
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
7
|
+
# assertions if you prefer.
|
8
|
+
config.expect_with :rspec do |expectations|
|
9
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
10
|
+
end
|
11
|
+
|
12
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
13
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
14
|
+
config.mock_with :rspec do |mocks|
|
15
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
16
|
+
# a real object. This is generally recommended, and will default to
|
17
|
+
# `true` in RSpec 4.
|
18
|
+
mocks.verify_partial_doubles = true
|
19
|
+
end
|
20
|
+
|
21
|
+
# The settings below are suggested to provide a good initial experience
|
22
|
+
# with RSpec, but feel free to customize to your heart's content.
|
23
|
+
# These two settings work together to allow you to limit a spec run
|
24
|
+
# to individual examples or groups you care about by tagging them with
|
25
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
26
|
+
# get run.
|
27
|
+
config.filter_run :focus
|
28
|
+
config.run_all_when_everything_filtered = true
|
29
|
+
|
30
|
+
config.warnings = true
|
31
|
+
|
32
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
33
|
+
# file, and it's useful to allow more verbose output when running an
|
34
|
+
# individual spec file.
|
35
|
+
if config.files_to_run.one?
|
36
|
+
# Use the documentation formatter for detailed output,
|
37
|
+
# unless a formatter has already been configured
|
38
|
+
# (e.g. via a command-line flag).
|
39
|
+
config.default_formatter = 'doc'
|
40
|
+
end
|
41
|
+
|
42
|
+
# Print the 10 slowest examples and example groups at the
|
43
|
+
# end of the spec run, to help surface which specs are running
|
44
|
+
# particularly slow.
|
45
|
+
config.profile_examples = 10
|
46
|
+
|
47
|
+
config.order = :random
|
48
|
+
Kernel.srand config.seed
|
49
|
+
|
50
|
+
def call_server(command, config = Pathname(__dir__).join("support/config.yml"))
|
51
|
+
system(Pathname(__dir__).join("../bin/rest-ftp-daemon -e test -c #{config} #{command}").to_s, chdir: __dir__) or fail "Could not #{command} server"
|
52
|
+
end
|
53
|
+
|
54
|
+
config.before :suite do
|
55
|
+
call_server(:start)
|
56
|
+
sleep 2
|
57
|
+
end
|
58
|
+
|
59
|
+
config.after :suite do
|
60
|
+
call_server(:stop)
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
test:
|
2
|
+
daemonize: true
|
3
|
+
port: 5678
|
4
|
+
workers: 2
|
5
|
+
adminpwd: "admin"
|
6
|
+
host: 127.0.0.1
|
7
|
+
|
8
|
+
transfer:
|
9
|
+
update_every_kb: 1024
|
10
|
+
notify_after_sec: 5
|
11
|
+
mkdir: true
|
12
|
+
tempfile: true
|
13
|
+
overwrite: false
|
14
|
+
timeout: 1800
|
15
|
+
|
16
|
+
debug:
|
17
|
+
ftp: false
|
18
|
+
|
19
|
+
logs:
|
20
|
+
thin: "./tmp/log/rftpd-environment-thin.log"
|
21
|
+
queue: "./tmp/log/rftpd-environment-core.log"
|
22
|
+
api: "./tmp/log/rftpd-environment-core.log"
|
23
|
+
workers: "./tmp/log/rftpd-environment-work.log"
|
24
|
+
jobs: "./tmp/log/rftpd-environment-work.log"
|
25
|
+
notify: "./tmp/log/rftpd-environment-work.log"
|
26
|
+
newrelic: "/var/log/rftpd-environment-newrelic.log"
|
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.222.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-
|
11
|
+
date: 2015-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: http
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.8'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: thin
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -215,6 +243,8 @@ extensions: []
|
|
215
243
|
extra_rdoc_files: []
|
216
244
|
files:
|
217
245
|
- ".gitignore"
|
246
|
+
- ".rspec"
|
247
|
+
- ".rubocop.yml"
|
218
248
|
- ".ruby-version"
|
219
249
|
- Gemfile
|
220
250
|
- Gemfile.lock
|
@@ -225,11 +255,9 @@ files:
|
|
225
255
|
- config.ru
|
226
256
|
- lib/rest-ftp-daemon.rb
|
227
257
|
- lib/rest-ftp-daemon/api/dashboard.rb
|
228
|
-
- lib/rest-ftp-daemon/api/debug.rb
|
229
258
|
- lib/rest-ftp-daemon/api/job_presenter.rb
|
230
259
|
- lib/rest-ftp-daemon/api/jobs.rb
|
231
260
|
- lib/rest-ftp-daemon/api/root.rb
|
232
|
-
- lib/rest-ftp-daemon/api/status.rb
|
233
261
|
- lib/rest-ftp-daemon/constants.rb
|
234
262
|
- lib/rest-ftp-daemon/exceptions.rb
|
235
263
|
- lib/rest-ftp-daemon/helpers.rb
|
@@ -258,6 +286,9 @@ files:
|
|
258
286
|
- lib/rest-ftp-daemon/worker_pool.rb
|
259
287
|
- rest-ftp-daemon.gemspec
|
260
288
|
- rest-ftp-daemon.yml.sample
|
289
|
+
- spec/rest-ftp-daemon/features/dashboard_spec.rb
|
290
|
+
- spec/spec_helper.rb
|
291
|
+
- spec/support/config.yml
|
261
292
|
homepage: http://github.com/bmedici/rest-ftp-daemon
|
262
293
|
licenses:
|
263
294
|
- MIT
|