Change Redis TTL to 1day. Fixing nitpicks

This commit is contained in:
Shinya Maeda 2018-04-06 19:30:23 +09:00
parent aaff5e452e
commit cffee49f7f
5 changed files with 14 additions and 13 deletions

View file

@ -9,7 +9,7 @@ module Ci
default_value_for :data_store, :redis default_value_for :data_store, :redis
CHUNK_SIZE = 128.kilobytes CHUNK_SIZE = 128.kilobytes
CHUNK_REDIS_TTL = 1.month CHUNK_REDIS_TTL = 1.day
enum data_store: { enum data_store: {
redis: 1, redis: 1,
@ -27,7 +27,7 @@ module Ci
end end
def set_data(value) def set_data(value)
raise 'too much data' if value.bytesize > CHUNK_SIZE raise ArgumentError, 'too much data' if value.bytesize > CHUNK_SIZE
if redis? if redis?
redis_set_data(value) redis_set_data(value)
@ -46,9 +46,9 @@ module Ci
end end
def append(new_data, offset) def append(new_data, offset)
current_data = self.data || "" current_data = self.data.to_s
raise 'Offset is out of bound' if offset > current_data.bytesize || offset < 0 raise ArgumentError, 'Offset is out of bound' if offset > current_data.bytesize || offset < 0
raise 'Outside of chunk size' if CHUNK_SIZE < offset + new_data.bytesize raise ArgumentError, 'Outside of chunk size' if CHUNK_SIZE < offset + new_data.bytesize
self.set_data(current_data.byteslice(0, offset) + new_data) self.set_data(current_data.byteslice(0, offset) + new_data)
end end

View file

@ -52,7 +52,6 @@ module API
end end
def job_token_valid?(job) def job_token_valid?(job)
# binding.pry
token = (params[JOB_TOKEN_PARAM] || env[JOB_TOKEN_HEADER]).to_s token = (params[JOB_TOKEN_PARAM] || env[JOB_TOKEN_HEADER]).to_s
token && job.valid_token?(token) token && job.valid_token?(token)
end end

View file

@ -19,7 +19,7 @@ module Gitlab
@job = job @job = job
@chunks_cache = [] @chunks_cache = []
@tell = 0 @tell = 0
@size = job_chunks.last.try(&:end_offset).to_i @size = calculate_size
yield self if block_given? yield self if block_given?
end end
@ -48,7 +48,7 @@ module Gitlab
-1 -1
end end
raise 'new position is outside of file' if new_pos < 0 || new_pos > size raise ArgumentError, 'new position is outside of file' if new_pos < 0 || new_pos > size
@tell = new_pos @tell = new_pos
end end
@ -135,7 +135,7 @@ module Gitlab
end end
def truncate(offset) def truncate(offset)
raise 'Outside of file' if offset > size raise ArgumentError, 'Outside of file' if offset > size
@tell = offset @tell = offset
@size = offset @size = offset
@ -221,6 +221,10 @@ module Gitlab
def job_chunks def job_chunks
::Ci::JobTraceChunk.where(job: job) ::Ci::JobTraceChunk.where(job: job)
end end
def calculate_size
job_chunks.order(chunk_index: :desc).last.try(&:end_offset).to_i
end
end end
end end
end end

View file

@ -334,14 +334,12 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
end end
context "#truncate" do context "#truncate" do
subject { chunked_io.truncate(offset) }
let(:offset) { 10 } let(:offset) { 10 }
context 'when data does not exist' do context 'when data does not exist' do
shared_examples 'truncates a trace' do shared_examples 'truncates a trace' do
it do it do
subject chunked_io.truncate(offset)
chunked_io.seek(0, IO::SEEK_SET) chunked_io.seek(0, IO::SEEK_SET)
expect(chunked_io.read).to eq(sample_trace_raw.byteslice(0, offset)) expect(chunked_io.read).to eq(sample_trace_raw.byteslice(0, offset))

View file

@ -116,7 +116,7 @@ describe Gitlab::Ci::Trace::Stream, :clean_gitlab_redis_cache do
end end
end end
context 'when stream is StringIO' do context 'when stream is Tempfile' do
let(:tempfile) { Tempfile.new } let(:tempfile) { Tempfile.new }
let(:stream) do let(:stream) do