diff --git a/lib/travis/api/v3/models/log.rb b/lib/travis/api/v3/models/log.rb index 75555014..b25b1558 100644 --- a/lib/travis/api/v3/models/log.rb +++ b/lib/travis/api/v3/models/log.rb @@ -1,6 +1,6 @@ module Travis::API::V3 - class Models::Log < Model - establish_connection 'logs_database' + class Models::Log < Model + establish_connection(Travis.config.logs_database) belongs_to :job belongs_to :removed_by, class_name: 'User', foreign_key: :removed_by has_many :log_parts, dependent: :destroy diff --git a/lib/travis/api/v3/models/log_part.rb b/lib/travis/api/v3/models/log_part.rb index 103ef0e1..054e4b8c 100644 --- a/lib/travis/api/v3/models/log_part.rb +++ b/lib/travis/api/v3/models/log_part.rb @@ -1,6 +1,6 @@ module Travis::API::V3 class Models::LogPart < Model - establish_connection 'logs_database' + establish_connection(Travis.config.logs_database) belongs_to :log end end diff --git a/lib/travis/api/v3/queries/log.rb b/lib/travis/api/v3/queries/log.rb index 464f78c5..1a67b8b3 100644 --- a/lib/travis/api/v3/queries/log.rb +++ b/lib/travis/api/v3/queries/log.rb @@ -5,9 +5,9 @@ module Travis::API::V3 def find(job) #check for the log in the Logs DB - log = Models::Log.find_by_job_id + log = Models::Log.find_by_job_id(job.id) #if the log exists and has not been archived yet, then collect the log_parts and return the Log query object - unless !log.archived_at.nil? + if !log.archived_at.nil? 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) diff --git a/lib/travis/config/defaults.rb b/lib/travis/config/defaults.rb index a322f94b..18e43798 100644 --- a/lib/travis/config/defaults.rb +++ b/lib/travis/config/defaults.rb @@ -18,6 +18,7 @@ module Travis assets: { host: HOSTS[Travis.env.to_sym] }, 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 } }, + 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: '' }, pusher: { app_id: 'app-id', key: 'key', secret: 'secret' }, sidekiq: { namespace: 'sidekiq', pool_size: 1 }, diff --git a/spec/v3/services/log/find_spec.rb b/spec/v3/services/log/find_spec.rb index 6b1bc155..5721dc06 100644 --- a/spec/v3/services/log/find_spec.rb +++ b/spec/v3/services/log/find_spec.rb @@ -10,9 +10,8 @@ describe Travis::API::V3::Services::Log::Find, set_app: true do let(:parsed_body) { JSON.load(body) } context 'when log stored in db' do - describe 'returns log as plain text' do + describe 'returns log as array of Log Parts' do let(:log) { job.log } - before { get("/v3/job/#{job.id}/log", {}, headers) } example { expect(last_response).to be_ok }