mirror of
https://github.com/gitlabhq/gitlabhq.git
synced 2025-08-03 16:37:48 +00:00
30 lines
683 B
Ruby
30 lines
683 B
Ruby
# frozen_string_literal: true
|
|
|
|
module ClickHouse
|
|
module WriteBuffer
|
|
extend Gitlab::Redis::BackwardsCompatibility
|
|
|
|
BUFFER_KEY_PREFIX = 'clickhouse_write_buffer_'
|
|
|
|
class << self
|
|
def add(table_name, event_hash)
|
|
Gitlab::Redis::SharedState.with do |redis|
|
|
redis.rpush(buffer_key(table_name), event_hash.to_json)
|
|
end
|
|
end
|
|
|
|
def pop(table_name, limit)
|
|
Array.wrap(lpop_with_limit(buffer_key(table_name), limit)).map do |hash|
|
|
Gitlab::Json.parse(hash, symbolize_names: true)
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def buffer_key(table_name)
|
|
"#{BUFFER_KEY_PREFIX}#{table_name}"
|
|
end
|
|
end
|
|
end
|
|
end
|