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

View File

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

View File

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

View File

@ -334,14 +334,12 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
end
context "#truncate" do
subject { chunked_io.truncate(offset) }
let(:offset) { 10 }
context 'when data does not exist' do
shared_examples 'truncates a trace' do
it do
subject
chunked_io.truncate(offset)
chunked_io.seek(0, IO::SEEK_SET)
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
context 'when stream is StringIO' do
context 'when stream is Tempfile' do
let(:tempfile) { Tempfile.new }
let(:stream) do