rest-ftp-daemon 0.250.5 → 0.300.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +19 -14
- data/README.md +12 -3
- data/bin/rest-ftp-daemon +102 -96
- data/config.ru +5 -5
- data/defaults.yml +61 -0
- data/lib/rest-ftp-daemon.rb +10 -4
- data/lib/rest-ftp-daemon/api/config.rb +3 -2
- data/lib/rest-ftp-daemon/api/dashboard.rb +1 -4
- data/lib/rest-ftp-daemon/api/debug.rb +30 -17
- data/lib/rest-ftp-daemon/api/job_presenter.rb +0 -2
- data/lib/rest-ftp-daemon/api/jobs.rb +4 -3
- data/lib/rest-ftp-daemon/api/root.rb +7 -10
- data/lib/rest-ftp-daemon/api/status.rb +7 -13
- data/lib/rest-ftp-daemon/constants.rb +27 -45
- data/lib/rest-ftp-daemon/counters.rb +0 -4
- data/lib/rest-ftp-daemon/helpers.rb +3 -18
- data/lib/rest-ftp-daemon/job.rb +16 -21
- data/lib/rest-ftp-daemon/job_queue.rb +21 -14
- data/lib/rest-ftp-daemon/launcher.rb +26 -0
- data/lib/rest-ftp-daemon/logger_pool.rb +9 -19
- data/lib/rest-ftp-daemon/metrics.rb +41 -0
- data/lib/rest-ftp-daemon/notification.rb +7 -10
- data/lib/rest-ftp-daemon/remote.rb +4 -4
- data/lib/rest-ftp-daemon/remote_ftp.rb +10 -10
- data/lib/rest-ftp-daemon/remote_sftp.rb +13 -24
- data/lib/rest-ftp-daemon/views/dashboard.haml +2 -2
- data/lib/rest-ftp-daemon/views/dashboard_footer.haml +2 -2
- data/lib/rest-ftp-daemon/views/dashboard_header.haml +2 -2
- data/lib/rest-ftp-daemon/views/dashboard_workers.haml +2 -2
- data/lib/rest-ftp-daemon/worker.rb +43 -12
- data/lib/rest-ftp-daemon/worker_conchita.rb +15 -28
- data/lib/rest-ftp-daemon/worker_job.rb +30 -21
- data/lib/rest-ftp-daemon/worker_pool.rb +59 -50
- data/lib/rest-ftp-daemon/worker_reporter.rb +70 -0
- data/lib/shared/conf.rb +195 -0
- data/lib/shared/logger_formatter.rb +31 -0
- data/lib/shared/logger_helper.rb +78 -0
- data/rest-ftp-daemon.gemspec +23 -22
- data/{rest-ftp-daemon.yml.sample → rest-ftp-daemon.sample.yml} +10 -7
- data/spec/spec_helper.rb +1 -1
- metadata +30 -12
- data/lib/rest-ftp-daemon/logger.rb +0 -57
- data/lib/rest-ftp-daemon/logger_helper.rb +0 -36
- data/lib/rest-ftp-daemon/settings.rb +0 -57
data/lib/rest-ftp-daemon.rb
CHANGED
@@ -9,25 +9,31 @@ require "syslog"
|
|
9
9
|
require "net/http"
|
10
10
|
require "thread"
|
11
11
|
require "singleton"
|
12
|
-
require "newrelic_rpm"
|
13
12
|
require "grape"
|
14
13
|
require "grape-entity"
|
14
|
+
require "newrelic_rpm"
|
15
|
+
|
16
|
+
|
17
|
+
# Shared libs
|
18
|
+
require_relative "shared/logger_formatter"
|
19
|
+
require_relative "shared/logger_helper"
|
20
|
+
require_relative "shared/conf"
|
21
|
+
|
15
22
|
|
16
23
|
# Project's libs
|
17
24
|
require_relative "rest-ftp-daemon/constants"
|
18
25
|
require_relative "rest-ftp-daemon/array"
|
19
|
-
require_relative "rest-ftp-daemon/settings"
|
20
26
|
require_relative "rest-ftp-daemon/exceptions"
|
21
27
|
require_relative "rest-ftp-daemon/helpers"
|
22
|
-
require_relative "rest-ftp-daemon/logger_helper"
|
23
28
|
require_relative "rest-ftp-daemon/logger_pool"
|
24
|
-
require_relative "rest-ftp-daemon/
|
29
|
+
require_relative "rest-ftp-daemon/metrics"
|
25
30
|
require_relative "rest-ftp-daemon/paginate"
|
26
31
|
require_relative "rest-ftp-daemon/uri"
|
27
32
|
require_relative "rest-ftp-daemon/job_queue"
|
28
33
|
require_relative "rest-ftp-daemon/counters"
|
29
34
|
require_relative "rest-ftp-daemon/worker"
|
30
35
|
require_relative "rest-ftp-daemon/worker_conchita"
|
36
|
+
require_relative "rest-ftp-daemon/worker_reporter"
|
31
37
|
require_relative "rest-ftp-daemon/worker_job"
|
32
38
|
require_relative "rest-ftp-daemon/worker_pool"
|
33
39
|
require_relative "rest-ftp-daemon/job"
|
@@ -2,6 +2,7 @@ module RestFtpDaemon
|
|
2
2
|
module API
|
3
3
|
class Config < Grape::API
|
4
4
|
|
5
|
+
### ENDPOINTS
|
5
6
|
desc "Show daemon config"
|
6
7
|
get "/" do
|
7
8
|
status 200
|
@@ -10,8 +11,8 @@ module RestFtpDaemon
|
|
10
11
|
|
11
12
|
desc "Reload daemon config"
|
12
13
|
post "/reload" do
|
13
|
-
if
|
14
|
-
|
14
|
+
if Conf.at(:debug, :allow_reload)==true
|
15
|
+
Conf.reload!
|
15
16
|
status 200
|
16
17
|
return Helpers.get_censored_config
|
17
18
|
else
|
@@ -5,14 +5,12 @@ require "facter"
|
|
5
5
|
|
6
6
|
module RestFtpDaemon
|
7
7
|
module API
|
8
|
-
|
9
8
|
class Dashbaord < Grape::API
|
10
9
|
|
11
10
|
### HELPERS
|
12
|
-
|
13
11
|
helpers do
|
14
12
|
def render name, values={}
|
15
|
-
template = File.read("#{
|
13
|
+
template = File.read("#{Conf.app_libs}/views/#{name}.haml")
|
16
14
|
|
17
15
|
haml_engine = Haml::Engine.new(template, encoding: Encoding::UTF_8)
|
18
16
|
#:encoding => Encoding::ASCII_8BIT
|
@@ -56,7 +54,6 @@ module RestFtpDaemon
|
|
56
54
|
|
57
55
|
end
|
58
56
|
|
59
|
-
|
60
57
|
### DASHBOARD
|
61
58
|
desc "Show a global dashboard"
|
62
59
|
get "/" do
|
@@ -2,33 +2,46 @@ module RestFtpDaemon
|
|
2
2
|
module API
|
3
3
|
class Debug < Grape::API
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
### HELPERS
|
6
|
+
helpers do
|
7
|
+
|
8
|
+
def debug_metrics
|
9
|
+
Metrics.sample
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
#
|
13
|
-
|
12
|
+
def debug_encodings
|
13
|
+
# Encodings
|
14
|
+
encodings = {}
|
15
|
+
jobs = $queue.jobs
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
+
jobs.each do |job|
|
18
|
+
# here = out[job.id] = {}
|
19
|
+
me = encodings[job.id] = {}
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
me[name] = value.encoding.to_s if value.is_a? String
|
21
|
-
end
|
21
|
+
me[:error] = job.error.encoding.to_s unless job.error.nil?
|
22
|
+
me[:status] = job.status.encoding.to_s unless job.status.nil?
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
Job::FIELDS.each do |name|
|
25
|
+
value = job.send(name)
|
26
|
+
me[name] = value.encoding.to_s if value.is_a? String
|
27
|
+
end
|
28
|
+
|
29
|
+
job.infos.each do |name, value|
|
30
|
+
me["infos_#{name}"] = value.encoding.to_s if value.is_a? String
|
31
|
+
end
|
25
32
|
end
|
26
33
|
end
|
27
34
|
|
35
|
+
end
|
36
|
+
|
37
|
+
### ENDPOINTS
|
38
|
+
desc "debug"
|
39
|
+
get "/" do
|
28
40
|
# Build response
|
29
41
|
return {
|
42
|
+
metrics: debug_metrics,
|
30
43
|
routes: RestFtpDaemon::API::Root.routes,
|
31
|
-
encodings:
|
44
|
+
encodings: debug_encodings,
|
32
45
|
}
|
33
46
|
end
|
34
47
|
|
@@ -2,6 +2,7 @@ module RestFtpDaemon
|
|
2
2
|
module API
|
3
3
|
class Jobs < Grape::API
|
4
4
|
|
5
|
+
### ENDPOINTS
|
5
6
|
desc "Read job with ID"
|
6
7
|
params do
|
7
8
|
requires :id, type: String, desc: "ID of the Job to read"
|
@@ -56,15 +57,15 @@ module RestFtpDaemon
|
|
56
57
|
optional :overwrite,
|
57
58
|
type: Boolean,
|
58
59
|
desc: "Overwrites files at target server",
|
59
|
-
default:
|
60
|
+
default: Conf.at(:transfer, :overwrite)
|
60
61
|
optional :mkdir,
|
61
62
|
type: Boolean,
|
62
63
|
desc: "Create missing directories on target server",
|
63
|
-
default:
|
64
|
+
default: Conf.at(:transfer, :mkdir)
|
64
65
|
optional :tempfile,
|
65
66
|
type: Boolean,
|
66
67
|
desc: "Upload to a temp file before renaming it to the target filename",
|
67
|
-
default:
|
68
|
+
default: Conf.at(:transfer, :tempfile)
|
68
69
|
end
|
69
70
|
post "/" do
|
70
71
|
# log_debug params.to_json
|
@@ -3,8 +3,11 @@ module RestFtpDaemon
|
|
3
3
|
class Root < Grape::API
|
4
4
|
|
5
5
|
### LOGGING & HELPERS
|
6
|
-
|
7
6
|
helpers do
|
7
|
+
def log_prefix
|
8
|
+
['API', nil, nil]
|
9
|
+
end
|
10
|
+
|
8
11
|
def logger
|
9
12
|
Root.logger
|
10
13
|
end
|
@@ -18,7 +21,7 @@ module RestFtpDaemon
|
|
18
21
|
request_method = env['REQUEST_METHOD']
|
19
22
|
request_path = env['REQUEST_PATH']
|
20
23
|
request_uri = env['REQUEST_URI']
|
21
|
-
log_info
|
24
|
+
log_info "HTTP #{request_method} #{request_uri}", params
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
@@ -26,10 +29,8 @@ module RestFtpDaemon
|
|
26
29
|
log_request
|
27
30
|
end
|
28
31
|
|
29
|
-
|
30
32
|
### CLASS CONFIG
|
31
|
-
|
32
|
-
helpers RestFtpDaemon::LoggerHelper
|
33
|
+
helpers Shared::LoggerHelper
|
33
34
|
logger RestFtpDaemon::LoggerPool.instance.get :api
|
34
35
|
do_not_route_head!
|
35
36
|
do_not_route_options!
|
@@ -39,7 +40,6 @@ module RestFtpDaemon
|
|
39
40
|
|
40
41
|
|
41
42
|
### MOUNTPOINTS
|
42
|
-
|
43
43
|
mount RestFtpDaemon::API::Status => MOUNT_STATUS
|
44
44
|
mount RestFtpDaemon::API::Jobs => MOUNT_JOBS
|
45
45
|
mount RestFtpDaemon::API::Dashbaord => MOUNT_BOARD
|
@@ -48,9 +48,7 @@ module RestFtpDaemon
|
|
48
48
|
|
49
49
|
|
50
50
|
### INITIALIZATION
|
51
|
-
|
52
51
|
def initialize
|
53
|
-
# Call daddy
|
54
52
|
super
|
55
53
|
|
56
54
|
# Check that Queue and Pool are available
|
@@ -59,8 +57,7 @@ module RestFtpDaemon
|
|
59
57
|
end
|
60
58
|
|
61
59
|
|
62
|
-
###
|
63
|
-
|
60
|
+
### ENDPOINTS
|
64
61
|
get "/" do
|
65
62
|
redirect Helpers.dashboard_filter_url()
|
66
63
|
end
|
@@ -4,9 +4,9 @@ module RestFtpDaemon
|
|
4
4
|
module API
|
5
5
|
class Status < Grape::API
|
6
6
|
|
7
|
+
### ENDPOINTS
|
7
8
|
desc "Show daemon status"
|
8
9
|
get "/" do
|
9
|
-
mem = GetProcessMem.new
|
10
10
|
status 200
|
11
11
|
|
12
12
|
# Get counters
|
@@ -23,24 +23,18 @@ module RestFtpDaemon
|
|
23
23
|
|
24
24
|
# Generate sutrcture
|
25
25
|
return {
|
26
|
+
name: Conf.app_name,
|
27
|
+
version: Conf.app_ver,
|
28
|
+
started: Conf.app_started,
|
26
29
|
hostname: `hostname`.to_s.chomp,
|
27
|
-
version: APP_VER,
|
28
|
-
|
29
|
-
started: APP_STARTED,
|
30
|
-
uptime: (Time.now - APP_STARTED).round(1),
|
31
|
-
|
32
|
-
memory_bytes: mem.bytes.to_i,
|
33
|
-
memory_mb: mem.mb.round(0),
|
34
|
-
|
35
|
-
status: $queue.jobs_by_status,
|
36
30
|
jobs_count: $queue.jobs_count,
|
37
31
|
|
38
|
-
|
32
|
+
metrics: Metrics.sample,
|
39
33
|
|
40
|
-
|
41
|
-
rate_by_targethost: $queue.rate_by(:targethost),
|
34
|
+
counters: counters,
|
42
35
|
|
43
36
|
workers: $pool.worker_variables,
|
37
|
+
|
44
38
|
}
|
45
39
|
end
|
46
40
|
|
@@ -1,31 +1,11 @@
|
|
1
|
-
#
|
2
|
-
APP_NAME = "rest-ftp-daemon"
|
3
|
-
APP_NICK = "rftpd"
|
4
|
-
APP_VER = "0.250.5"
|
5
|
-
|
6
|
-
# Provide default config file information
|
7
|
-
APP_LIB = File.expand_path(File.dirname(__FILE__))
|
8
|
-
APP_ROOT = File.expand_path(File.dirname(__FILE__) + "/../../")
|
9
|
-
|
10
|
-
DEFAULT_CONFIG_PATH = File.expand_path "/etc/#{APP_NAME}.yml"
|
11
|
-
SAMPLE_CONFIG_FILE = File.expand_path(File.join File.dirname(__FILE__), "/../../rest-ftp-daemon.yml.sample")
|
12
|
-
|
13
|
-
TAIL_MESSAGE = <<EOD
|
14
|
-
|
15
|
-
A default configuration is available here: #{SAMPLE_CONFIG_FILE}.
|
16
|
-
You should copy it to the expected location #{DEFAULT_CONFIG_PATH}:
|
17
|
-
|
18
|
-
sudo cp #{SAMPLE_CONFIG_FILE} #{DEFAULT_CONFIG_PATH}
|
19
|
-
EOD
|
1
|
+
# Misc constants
|
20
2
|
|
21
3
|
|
22
4
|
# Configuration defaults
|
23
|
-
# DEFAULT_WORKERS = 2
|
24
5
|
DEFAULT_POOL = "default"
|
25
|
-
DEFAULT_WORKER_TIMEOUT = 1800 # 1h
|
26
6
|
DEFAULT_SFTP_TIMEOUT = 600 # 10mn
|
27
7
|
DEFAULT_FTP_CHUNK = 1024 # 1 MB
|
28
|
-
DEFAULT_PAGE_SIZE =
|
8
|
+
DEFAULT_PAGE_SIZE = 50 # 50 lines
|
29
9
|
DEFAULT_RETRY_DELAY = 10 # 10s
|
30
10
|
|
31
11
|
|
@@ -36,6 +16,29 @@ JOB_TEMPFILE_LEN = 8
|
|
36
16
|
JOB_UPDATE_INTERVAL = 1
|
37
17
|
|
38
18
|
|
19
|
+
# Constants: logger
|
20
|
+
LOG_ROTATION = "daily"
|
21
|
+
LOG_FORMAT_PROGNAME = "%d\t%s"
|
22
|
+
|
23
|
+
LOG_HEADER_TIME = "%Y-%m-%d %H:%M:%S"
|
24
|
+
LOG_HEADER_FORMAT = "%s \t%d\t%-8s %-15s "
|
25
|
+
LOG_MESSAGE_TRIM = 200
|
26
|
+
LOG_MESSAGE_TEXT = "%s%s"
|
27
|
+
LOG_MESSAGE_ARRAY = "%s - %s"
|
28
|
+
LOG_MESSAGE_HASH = "%s * %-20s %s"
|
29
|
+
|
30
|
+
# Constants: logger app-specific prefix
|
31
|
+
LOG_PREFIX_WID = 8
|
32
|
+
LOG_PREFIX_JID = JOB_IDENT_LEN + 3 + 2
|
33
|
+
LOG_PREFIX_ID = 6
|
34
|
+
LOG_PREFIX_FORMAT = "%#{-LOG_PREFIX_WID.to_i}s %#{-LOG_PREFIX_JID.to_i}s %#{-LOG_PREFIX_ID.to_i}s"
|
35
|
+
|
36
|
+
|
37
|
+
# Constants: logger to be cleaned up
|
38
|
+
LOG_PIPE_LEN = 10
|
39
|
+
LOG_INDENT = "\t"
|
40
|
+
|
41
|
+
|
39
42
|
# Jobs statuses
|
40
43
|
JOB_STATUS_PREPARING = "preparing"
|
41
44
|
JOB_STATUS_RUNNING = "running"
|
@@ -73,6 +76,7 @@ WORKER_STATUS_FINISHED = "finished"
|
|
73
76
|
WORKER_STATUS_TIMEOUT = "timeout"
|
74
77
|
WORKER_STATUS_CRASHED = "crashed"
|
75
78
|
WORKER_STATUS_CLEANING = "cleaning"
|
79
|
+
WORKER_STATUS_REPORTING = "reporting"
|
76
80
|
WORKER_STYLES = {
|
77
81
|
WORKER_STATUS_WAITING => nil,
|
78
82
|
WORKER_STATUS_RUNNING => :info,
|
@@ -81,23 +85,7 @@ WORKER_STYLES = {
|
|
81
85
|
}
|
82
86
|
|
83
87
|
|
84
|
-
#
|
85
|
-
LOG_PIPE_LEN = 10
|
86
|
-
LOG_COL_WID = 8
|
87
|
-
LOG_COL_JID = JOB_IDENT_LEN + 3 + 2
|
88
|
-
LOG_COL_ID = 6
|
89
|
-
LOG_TRIM_LINE = 200
|
90
|
-
LOG_DUMPS = File.dirname(__FILE__) + "/../../log/"
|
91
|
-
LOG_ROTATION = "daily"
|
92
|
-
LOG_FORMAT_TIME = "%Y-%m-%d %H:%M:%S"
|
93
|
-
LOG_FORMAT_PREFIX = "%s %s\t%-#{LOG_PIPE_LEN.to_i}s\t"
|
94
|
-
LOG_FORMAT_MESSAGE = "%#{-LOG_COL_WID.to_i}s\t%#{-LOG_COL_JID.to_i}s\t%#{-LOG_COL_ID.to_i}s"
|
95
|
-
LOG_NEWLINE = "\n"
|
96
|
-
LOG_INDENT = "\t"
|
97
|
-
BIND_PORT_TIMEOUT = 3
|
98
|
-
BIND_PORT_LOCALHOST = "127.0.0.1"
|
99
|
-
|
100
|
-
ENV_PRODUCTION = "production"
|
88
|
+
# API mountpoints
|
101
89
|
MOUNT_JOBS = "/jobs"
|
102
90
|
MOUNT_BOARD = "/board"
|
103
91
|
MOUNT_STATUS = "/status"
|
@@ -107,10 +95,4 @@ MOUNT_CONFIG = "/config"
|
|
107
95
|
|
108
96
|
# Notifications
|
109
97
|
NOTIFY_PREFIX = "rftpd"
|
110
|
-
NOTIFY_USERAGENT = "#{APP_NAME}/v#{APP_VER}"
|
111
98
|
NOTIFY_IDENTIFIER_LEN = 4
|
112
|
-
|
113
|
-
|
114
|
-
# Initialize defaults
|
115
|
-
APP_STARTED = Time.now
|
116
|
-
APP_LIBS = File.dirname(__FILE__)
|
@@ -2,9 +2,9 @@ module RestFtpDaemon
|
|
2
2
|
class Helpers
|
3
3
|
|
4
4
|
def self.get_censored_config
|
5
|
-
config =
|
6
|
-
config[:users] =
|
7
|
-
config[:endpoints] =
|
5
|
+
config = Conf.to_hash
|
6
|
+
config[:users] = Conf[:users].keys if Conf[:users]
|
7
|
+
config[:endpoints] = Conf[:endpoints].keys if Conf[:endpoints]
|
8
8
|
config
|
9
9
|
end
|
10
10
|
|
@@ -60,21 +60,6 @@ module RestFtpDaemon
|
|
60
60
|
return m[1], m[2] unless m.nil?
|
61
61
|
end
|
62
62
|
|
63
|
-
def self.local_port_used? port
|
64
|
-
Timeout.timeout(BIND_PORT_TIMEOUT) do
|
65
|
-
begin
|
66
|
-
TCPSocket.new(BIND_PORT_LOCALHOST, port).close
|
67
|
-
true
|
68
|
-
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
69
|
-
false
|
70
|
-
rescue Errno::EADDRNOTAVAIL
|
71
|
-
"Settings.local_port_used: Errno::EADDRNOTAVAIL"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
rescue Timeout::Error
|
75
|
-
false
|
76
|
-
end
|
77
|
-
|
78
63
|
def self.job_method_label method
|
79
64
|
return if method.nil?
|
80
65
|
klass = case method
|
data/lib/rest-ftp-daemon/job.rb
CHANGED
@@ -4,13 +4,9 @@ module RestFtpDaemon
|
|
4
4
|
|
5
5
|
# Reprensents work to be done along with parameters to process it
|
6
6
|
class Job
|
7
|
-
include LoggerHelper
|
7
|
+
include Shared::LoggerHelper
|
8
8
|
attr_reader :logger
|
9
9
|
|
10
|
-
if Settings.newrelic_enabled?
|
11
|
-
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
12
|
-
end
|
13
|
-
|
14
10
|
FIELDS = [:source, :target, :label, :priority, :pool, :notify, :overwrite, :mkdir, :tempfile]
|
15
11
|
|
16
12
|
attr_accessor :wid
|
@@ -59,7 +55,7 @@ module RestFtpDaemon
|
|
59
55
|
end
|
60
56
|
|
61
57
|
# Set pool
|
62
|
-
pools = (
|
58
|
+
pools = (Conf[:pools] || {})
|
63
59
|
# Check if pool name exists
|
64
60
|
if (pools.keys.include? params[:pool])
|
65
61
|
@pool = params[:pool].to_s
|
@@ -71,7 +67,7 @@ module RestFtpDaemon
|
|
71
67
|
reset
|
72
68
|
|
73
69
|
# Read source file size and parameters
|
74
|
-
@notify_after_sec =
|
70
|
+
@notify_after_sec = Conf.at(:transfer, :notify_after_sec) rescue nil
|
75
71
|
end
|
76
72
|
|
77
73
|
def reset
|
@@ -277,8 +273,8 @@ module RestFtpDaemon
|
|
277
273
|
|
278
274
|
def replace_tokens path
|
279
275
|
# Ensure endpoints are not a nil value
|
280
|
-
return path unless
|
281
|
-
vectors =
|
276
|
+
return path unless Conf[:endpoints].is_a? Enumerable
|
277
|
+
vectors = Conf[:endpoints].clone
|
282
278
|
|
283
279
|
# Stack RANDOM into tokens
|
284
280
|
vectors["RANDOM"] = SecureRandom.hex(JOB_RANDOM_LEN)
|
@@ -328,21 +324,21 @@ module RestFtpDaemon
|
|
328
324
|
# set_info :target, :method, :ftp
|
329
325
|
set_info :target, :method, JOB_METHOD_FTP
|
330
326
|
#@target_method = :ftp
|
331
|
-
@remote = RemoteFTP.new target_uri,
|
327
|
+
@remote = RemoteFTP.new target_uri, log_prefix
|
332
328
|
|
333
329
|
elsif (target_uri.is_a? URI::FTPES) || (target_uri.is_a? URI::FTPS)
|
334
330
|
log_info "Job.prepare target_method FTPES"
|
335
331
|
# set_info :target, :method, :ftpes
|
336
332
|
set_info :target, :method, JOB_METHOD_FTPS
|
337
333
|
# @target_method = :ftpes
|
338
|
-
@remote = RemoteFTP.new target_uri,
|
334
|
+
@remote = RemoteFTP.new target_uri, log_prefix, ftpes: true
|
339
335
|
|
340
336
|
elsif target_uri.is_a? URI::SFTP
|
341
337
|
log_info "Job.prepare target_method SFTP"
|
342
338
|
# set_info :target, :method, :sftp
|
343
339
|
set_info :target, :method, JOB_METHOD_SFTP
|
344
340
|
# @target_method = :sftp
|
345
|
-
@remote = RemoteSFTP.new target_uri,
|
341
|
+
@remote = RemoteSFTP.new target_uri, log_prefix
|
346
342
|
|
347
343
|
else
|
348
344
|
log_info "Job.prepare unknown scheme [#{target_uri.scheme}]"
|
@@ -413,11 +409,8 @@ module RestFtpDaemon
|
|
413
409
|
|
414
410
|
private
|
415
411
|
|
416
|
-
def
|
417
|
-
|
418
|
-
wid: @wid,
|
419
|
-
jid: @id,
|
420
|
-
}
|
412
|
+
def log_prefix
|
413
|
+
[@wid, @id, nil]
|
421
414
|
end
|
422
415
|
|
423
416
|
def find_local path
|
@@ -509,14 +502,14 @@ module RestFtpDaemon
|
|
509
502
|
tempname = nil
|
510
503
|
if @tempfile
|
511
504
|
tempname = "#{target.name}.temp-#{Helpers.identifier(JOB_TEMPFILE_LEN)}"
|
512
|
-
|
505
|
+
log_debug "Job.remote_push tempname [#{tempname}]"
|
513
506
|
end
|
514
507
|
|
515
508
|
# Remove any existing version if expected, or test its presence
|
516
509
|
if @overwrite
|
517
510
|
@remote.remove! target
|
518
511
|
elsif size = @remote.present?(target)
|
519
|
-
|
512
|
+
log_debug "Job.remote_push existing (#{Helpers.format_bytes size, 'B'})"
|
520
513
|
raise RestFtpDaemon::JobTargetFileExists
|
521
514
|
end
|
522
515
|
|
@@ -568,7 +561,7 @@ module RestFtpDaemon
|
|
568
561
|
stack << (Helpers.format_bytes @transfer_total, "B")
|
569
562
|
stack << (Helpers.format_bytes @current_bitrate.round(0), "bps")
|
570
563
|
stack2 = stack.map { |txt| ("%#{LOG_PIPE_LEN.to_i}s" % txt) }.join("\t")
|
571
|
-
|
564
|
+
log_debug "Job.progress #{stack2} \t#{name}"
|
572
565
|
|
573
566
|
# Remember when we last did it
|
574
567
|
@progress_at = now
|
@@ -665,7 +658,9 @@ module RestFtpDaemon
|
|
665
658
|
client_notify event, error: error, status: notif_status, message: "#{exception.class} | #{exception.message}"
|
666
659
|
end
|
667
660
|
|
668
|
-
|
661
|
+
# NewRelic instrumentation
|
662
|
+
if Conf.newrelic_enabled?
|
663
|
+
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
669
664
|
add_transaction_tracer :prepare, category: :task
|
670
665
|
add_transaction_tracer :run, category: :task
|
671
666
|
add_transaction_tracer :client_notify, category: :task
|