establish connection to logs db, update result, update query
This commit is contained in:
parent
7cb4b89883
commit
9b7da3519a
|
@ -1,5 +1,6 @@
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
class Models::Log < Model
|
class Models::Log < Model
|
||||||
|
establish_connection 'logs_database'
|
||||||
belongs_to :job
|
belongs_to :job
|
||||||
belongs_to :removed_by, class_name: 'User', foreign_key: :removed_by
|
belongs_to :removed_by, class_name: 'User', foreign_key: :removed_by
|
||||||
has_many :log_parts, dependent: :destroy
|
has_many :log_parts, dependent: :destroy
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
class Models::LogPart < Model
|
class Models::LogPart < Model
|
||||||
|
establish_connection 'logs_database'
|
||||||
belongs_to :log
|
belongs_to :log
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,24 +4,22 @@ module Travis::API::V3
|
||||||
require 'uri'
|
require 'uri'
|
||||||
|
|
||||||
def find(job)
|
def find(job)
|
||||||
#check for the log in the DB
|
#check for the log in the Logs DB
|
||||||
log = Models::Log.find_by_job_id
|
log = Models::Log.find_by_job_id
|
||||||
#if the log exists and has not been archived yet, then collect the log_parts and return the contents
|
#if the log exists and has not been archived yet, then collect the log_parts and return the Log query object
|
||||||
unless log.nil? || !log.archived_at.nil?
|
unless !log.archived_at.nil?
|
||||||
log_parts = Models::Log::Part.where(log_id: log.id)
|
log_parts = Models::LogPart.where(log_id: log.id).to_a
|
||||||
log_data = []
|
|
||||||
log_parts.each { |log_part| log_data << log_part.content }
|
|
||||||
log_data
|
|
||||||
elsif log.archived_at?
|
elsif log.archived_at?
|
||||||
# if it's not there then fetch it from S3.
|
## 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 = []
|
||||||
archived_log_data = []
|
# content.each_line do |line|
|
||||||
content.each_line do |line|
|
# log_parts << line.chop
|
||||||
archived_log_data << line.chop
|
# end
|
||||||
end
|
# log_parts
|
||||||
archived_log_data
|
else
|
||||||
|
raise EntityMissing, 'log not found'.freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ module Travis::API::V3
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user