Commit a2ccfa79 authored by Shinya Maeda's avatar Shinya Maeda
Browse files

Add TTL refresh worker

parent 8a7654a5
......@@ -4,14 +4,13 @@ module Ci
belongs_to :job, class_name: "Ci::Build", foreign_key: :job_id
after_destroy :redis_delete_data, if: :redis?
default_value_for :data_store, :redis
WriteError = Class.new(StandardError)
CHUNK_SIZE = 128.kilobytes
CHUNK_REDIS_TTL = 1.week
CHUNK_REDIS_TTL = 1.day
CHUNK_REDIS_TTL_REFRESH = 6.hours
LOCK_RETRY = 100
LOCK_SLEEP = 1
LOCK_TTL = 5.minutes
......@@ -87,6 +86,12 @@ module Ci
end
end
def redis_extend_ttl
Gitlab::Redis::SharedState.with do |redis|
redis.setex(redis_data_key, CHUNK_REDIS_TTL, data)
end
end
private
def schedule_to_db
......@@ -115,7 +120,7 @@ module Ci
Gitlab::Redis::SharedState.with do |redis|
redis.del(redis_data_key)
end
end
end
def redis_data_key
"gitlab:ci:trace:#{job_id}:chunks:#{chunk_index}:data"
......
class BuildTraceTTLRefreshWorker
include ApplicationWorker
include PipelineQueue
queue_namespace :pipeline_processing
def perform(job_trace_chunk_id_min, job_trace_chunk_id_max)
Ci::JobTraceChunk.redis
.where(:id => (job_trace_chunk_id_min..job_trace_chunk_id_max))
.map(&:redis_extend_ttl)
end
end
class BuildTraceTTLRefreshWorker
include ApplicationWorker
include CronjobQueue
def perform
Ci::JobTraceChunk.redis # Stored in redis
.joins(:ci_builds)
.where('NOT EXISTS (?)', # If the trace has not been archived yet
Ci::JobArtifact.select(1).trace.where('ci_builds.id = ci_job_artifacts.job_id'))
.where('ci_builds.update_at < ?', CHUNK_REDIS_TTL_REFRESH.ago) # If the live-trace has not been updated over 6h
.find_in_batches(batch_size: 1000) do |job_trace_chunks|
BuildTraceTTLExtendWorker.perform_async(job_trace_chunks.minimum(:id), job_trace_chunks.maximum(:id))
end
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment