add renderers for logpart and logparts, update log query, fix specs
This commit is contained in:
parent
a1fcf4995b
commit
85c9570b87
|
@ -6,26 +6,24 @@ module Travis::API::V3
|
||||||
def find(job)
|
def find(job)
|
||||||
#check for the log in the Logs DB
|
#check for the log in the Logs DB
|
||||||
log = Models::Log.find_by_job_id(job.id)
|
log = Models::Log.find_by_job_id(job.id)
|
||||||
|
|
||||||
|
raise EntityMissing, 'log not found'.freeze if log.nil?
|
||||||
|
|
||||||
#if the log exists and has not been archived yet, then collect the log_parts and return the Log query object
|
#if the log exists and has not been archived yet, then collect the log_parts and return the Log query object
|
||||||
if !log.archived_at.nil?
|
if log.archived_at
|
||||||
log_parts = Models::LogPart.where(log_id: log.id).to_a
|
|
||||||
elsif log.archived_at?
|
|
||||||
## if it's not there then fetch it from S3, and return it wrapped as a compatible log_parts object with a hard coded #number (log_parts have a number) and the parts chunked (not sure how to do this)
|
## if it's not there then fetch it from S3, and return it wrapped as a compatible log_parts object with a hard coded #number (log_parts have a number) and the parts chunked (not sure how to do this)
|
||||||
archived_log_path = archive_url("/jobs/#{params[:job.id]}/log.txt")
|
archived_log_path = archive_url("/jobs/#{params[:job.id]}/log.txt")
|
||||||
content = open(Net::HTTP.get(URI.parse(archived_log_path)))
|
content = open(Net::HTTP.get(URI.parse(archived_log_path)))
|
||||||
|
|
||||||
log_parts = []
|
log_parts = []
|
||||||
number = 0
|
|
||||||
|
|
||||||
content.each_line do |line|
|
content.each_line.with_index do |line, number|
|
||||||
log_part = Models::LogPart.new(id: nil, log_id: log.id, content: line.chomp, number: number, final: false, created_at: log.created_at)
|
log_part = Models::LogPart.new(log_id: log.id, content: line.chomp, number: number, created_at: log.created_at)
|
||||||
number += 1
|
|
||||||
log_parts << log_part
|
log_parts << log_part
|
||||||
end
|
end
|
||||||
log_parts
|
log.log_parts = log_parts
|
||||||
else
|
|
||||||
raise EntityMissing, 'log not found'.freeze
|
|
||||||
end
|
end
|
||||||
|
log
|
||||||
end
|
end
|
||||||
|
|
||||||
def archive_url(path)
|
def archive_url(path)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
require 'travis/api/v3/renderer/model_renderer'
|
|
||||||
|
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
class Renderer::Log < Renderer::ModelRenderer
|
class Renderer::Log < Renderer::ModelRenderer
|
||||||
representation(:standard, :id, :content)
|
representation(:minimal, :id, :content)
|
||||||
|
representation(:standard, *representations[:minimal], :log_parts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
6
lib/travis/api/v3/renderer/log_part.rb
Normal file
6
lib/travis/api/v3/renderer/log_part.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
module Travis::API::V3
|
||||||
|
class Renderer::LogPart < Renderer::ModelRenderer
|
||||||
|
representation(:minimal, :content, :number)
|
||||||
|
representation(:standard, *representations[:minimal], :log)
|
||||||
|
end
|
||||||
|
end
|
6
lib/travis/api/v3/renderer/log_parts.rb
Normal file
6
lib/travis/api/v3/renderer/log_parts.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
module Travis::API::V3
|
||||||
|
class Renderer::LogParts < Renderer::CollectionRenderer
|
||||||
|
type :log_parts
|
||||||
|
collection_key :log_parts
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,11 +1,8 @@
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
class Services::Log::Find < Service
|
class Services::Log::Find < Service
|
||||||
params :id, prefix: :job
|
|
||||||
|
|
||||||
def run!
|
def run!
|
||||||
job = find(:job)
|
job = find(:job)
|
||||||
query.find(job)
|
query.find(job)
|
||||||
result(log, parts: log_parts)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,7 +18,7 @@ module Travis
|
||||||
assets: { host: HOSTS[Travis.env.to_sym] },
|
assets: { host: HOSTS[Travis.env.to_sym] },
|
||||||
amqp: { username: 'guest', password: 'guest', host: 'localhost', prefetch: 1 },
|
amqp: { username: 'guest', password: 'guest', host: 'localhost', prefetch: 1 },
|
||||||
database: { adapter: 'postgresql', database: "travis_#{Travis.env}", encoding: 'unicode', min_messages: 'warning', variables: { statement_timeout: 10_000 } },
|
database: { adapter: 'postgresql', database: "travis_#{Travis.env}", encoding: 'unicode', min_messages: 'warning', variables: { statement_timeout: 10_000 } },
|
||||||
# logs_database: { adapter: 'postgresql', database: "travis_logs_#{Travis.env}", encoding: 'unicode', min_messages: 'warning', variables: { statement_timeout: 10_000 } },
|
logs_database: { adapter: 'postgresql', database: "travis_logs_#{Travis.env}", encoding: 'unicode', min_messages: 'warning', variables: { statement_timeout: 10_000 } },
|
||||||
s3: { access_key_id: '', secret_access_key: '' },
|
s3: { access_key_id: '', secret_access_key: '' },
|
||||||
pusher: { app_id: 'app-id', key: 'key', secret: 'secret' },
|
pusher: { app_id: 'app-id', key: 'key', secret: 'secret' },
|
||||||
sidekiq: { namespace: 'sidekiq', pool_size: 1 },
|
sidekiq: { namespace: 'sidekiq', pool_size: 1 },
|
||||||
|
|
|
@ -10,26 +10,25 @@ describe Travis::API::V3::Services::Log::Find, set_app: true do
|
||||||
let(:parsed_body) { JSON.load(body) }
|
let(:parsed_body) { JSON.load(body) }
|
||||||
|
|
||||||
context 'when log stored in db' do
|
context 'when log stored in db' do
|
||||||
describe 'returns log as array of Log Parts' do
|
describe 'returns the Log with an array of Log Parts' do
|
||||||
let(:log) { job.log }
|
let(:log) { job.log }
|
||||||
|
|
||||||
p log
|
|
||||||
|
|
||||||
before { get("/v3/job/#{job.id}/log", {}, headers) }
|
|
||||||
|
|
||||||
example { expect(last_response).to be_ok }
|
|
||||||
example do
|
example do
|
||||||
|
log_part = log.log_parts.create(content: "logging it", number: 0)
|
||||||
|
get("/v3/job/#{job.id}/log", {}, headers)
|
||||||
expect(parsed_body).to eq(
|
expect(parsed_body).to eq(
|
||||||
'@href' => "/v3/job/#{job.id}/log",
|
'@href' => "/v3/job/#{job.id}/log",
|
||||||
'@representation' => 'standard',
|
'@representation' => 'standard',
|
||||||
'@type' => 'log',
|
'@type' => 'log',
|
||||||
'content' => nil,
|
'content' => nil,
|
||||||
'id' => log.id
|
'id' => log.id,
|
||||||
)
|
'log_parts' => [{
|
||||||
|
"@type" => "log_part",
|
||||||
|
"@representation" => "minimal",
|
||||||
|
"content" => log_part.content,
|
||||||
|
"number" => log_part.number }])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'returns log as chunked json'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when log not found in db but stored on S3' do
|
context 'when log not found in db but stored on S3' do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user