Commit 6bd93d3e authored by Felipe Pina's avatar Felipe Pina
Browse files

Suporte para envio de log parcial de fluxo

Showing with 57 additions and 12 deletions
+57 -12
......@@ -238,7 +238,9 @@ posix.actions = {
for k,v in collect_exec_data(self, job) do
processes[1][k] = v
end
processes[1].log_chunk, processes[1].log_chunk_seq = logchunk.read(job)
for k,v in pairs(logchunk.read(job)) do
processes[1][k] = v
end
-- If command has finished, returns information for parent process
else
processes[1] = {
......
......@@ -4,24 +4,67 @@ local logchunk = {}
local util = require("sga.util")
local stat = require("posix.sys.stat")
function logchunk.read(job)
local file = job.parameters.csbase_command_output_path.."/out.log"
if not stat.stat(file) then
local function read_file(job, file)
local offset = (job.data[file] and job.data[file].chunk_offset) or 0
local seq = (job.data[file] and job.data[file].chunk_seq) or 0
local chunk = util.read_file(file, offset)
if not chunk then
return nil
end
local offset = job.data.chunk_offset or 0
local seq = job.data.chunk_seq or 0
if not job.data[file] then
job.data[file] = {}
end
local data = job.data[file]
data.chunk_offset = offset + chunk:len()
data.chunk_seq = seq + 1
local chunk = util.read_file(file, offset)
if not chunk then
return nil, nil
return chunk, data.chunk_seq
end
local function single(job)
local filename = "out.log"
local filepath = job.parameters.csbase_command_output_path.."/"..filename
if not stat.stat(filepath) then
return {}
else
local chunk, chunk_seq = read_file(job, filepath)
if chunk then
return { log_chunk = chunk, log_chunk_seq = chunk_seq }
else
return {}
end
end
end
job.data.chunk_offset = offset + chunk:len()
job.data.chunk_seq = seq + 1
local function multiple(job)
local ret = {}
local fileformat = "out%d.log"
for i=0,100 do
local filename = string.format(fileformat, i)
local filepath = job.parameters.csbase_command_output_path.."/"..filename
print(i)
if not stat.stat(filepath) then
break
else
local chunk, chunk_seq = read_file(job, filepath)
if chunk then
ret["log_chunk."..i] = chunk
ret["log_chunk_seq."..i] = chunk_seq
end
end
end
return ret
end
return chunk, job.data.chunk_seq
function logchunk.read(job)
local singlelog = single(job)
local multiplelog = multiple(job)
for k,v in pairs(singlelog) do
multiplelog[k] = v
end
return multiplelog
end
return logchunk
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment