Skip to content

Commit

Permalink
chore: move log transfer to log_runtime_archive
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardacoppo committed Dec 5, 2024
1 parent 513e480 commit 34a737c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
20 changes: 20 additions & 0 deletions lib/syskit/cli/log_runtime_archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ def process_root_folder
end
end

# Transfer logs from a process server to the main computer server
#
# @param [Pathname] src_dir the log folder on the process server
# @param [Params] server_params the FTP server parameters:
# { host, port, certificate, user, password }
def process_transfer(src_dir, server_params)
socket =
begin TCPSocket.new(server_params[:host], server_params[:port])
rescue Errno::ECONNREFUSED => e
raise e.class, "cannot contact process server at " \
"'#{host}:#{port}': #{e.message}"
end
socket.write(COMMAND_LOG_UPLOAD_FILE)

candidates = self.class.find_all_dataset_folders(src_dir)
candidates.each do |child|
Marshal.dump([server_params, Pathname(child)], socket)
end
end

# Manages folder available space
#
# The method will check if there is enough space to save more log files
Expand Down
41 changes: 40 additions & 1 deletion lib/syskit/cli/log_runtime_archive_main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def self.exit_on_failure?
end

desc "watch", "watch a dataset root folder and call archiver"

option :period,
type: :numeric, default: 600, desc: "polling period in seconds"
option :max_size,
Expand Down Expand Up @@ -61,6 +60,39 @@ def archive(root_dir, target_dir)
archiver.process_root_folder
end

desc "watch_transfer", "watches a dataset root folder \
and periodically performs transfer"
option :period,
type: :numeric, default: 600, desc: "polling period in seconds"
default_task def watch_transfer(src_dir, tgt_dir, server_params)
loop do
begin
transfer(src_dir, tgt_dir, server_params)
rescue Errno::ENOSPC
next
end

puts "Transferred pending logs, sleeping #{options[:period]}s"
sleep options[:period]
end
end

desc "transfer", "transfers the datasets"
# TODO: manage disk space
def transfer(src_dir, tgt_dir, server_params)
src_dir = validate_directory_exists(src_dir)
tgt_dir = validate_directory_exists(tgt_dir)
archiver = make_archiver(src_dir, tgt_dir)

archiver.process_transfer(src_dir, server_params)
end

desc "transfer_server", "creates the log transfer FTP server \
that runs on the main computer"
def transfer_server(tgt_dir, user, password)
create_server(tgt_dir, user, password)
end

no_commands do
def validate_directory_exists(dir)
dir = Pathname.new(dir)
Expand All @@ -80,6 +112,13 @@ def make_archiver(root_dir, target_dir)
logger: logger, max_archive_size: options[:max_size] * (1024**2)
)
end

def create_server(tgt_dir, user, password)
server = LogTransferServer::SpawnServer.new(
tgt_dir, user, password, nil
)
server.run
end
end
end
end
Expand Down

0 comments on commit 34a737c

Please sign in to comment.