debian-mirror-gitlab/app/workers/gitlab_performance_bar_stats_worker.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
962 B
Ruby
Raw Normal View History

2021-02-22 17:27:13 +05:30
# frozen_string_literal: true
class GitlabPerformanceBarStatsWorker
include ApplicationWorker
2021-10-27 15:23:28 +05:30
data_consistency :always
worker_resource_boundary :cpu
2021-06-08 01:23:25 +05:30
sidekiq_options retry: 3
2021-02-22 17:27:13 +05:30
LEASE_KEY = 'gitlab:performance_bar_stats'
LEASE_TIMEOUT = 600
WORKER_DELAY = 120
STATS_KEY = 'performance_bar_stats:pending_request_ids'
2021-03-08 18:12:59 +05:30
STATS_KEY_EXPIRE = 30.minutes.to_i
2021-02-22 17:27:13 +05:30
feature_category :metrics
idempotent!
def perform(lease_uuid)
2023-01-13 00:05:48 +05:30
with_redis do |redis|
2021-02-22 17:27:13 +05:30
request_ids = fetch_request_ids(redis, lease_uuid)
stats = Gitlab::PerformanceBar::Stats.new(redis)
request_ids.each do |id|
stats.process(id)
end
end
end
private
2023-01-13 00:05:48 +05:30
def with_redis(&block)
Gitlab::Redis::Cache.with(&block) # rubocop:disable CodeReuse/ActiveRecord
end
2021-02-22 17:27:13 +05:30
def fetch_request_ids(redis, lease_uuid)
ids = redis.smembers(STATS_KEY)
redis.del(STATS_KEY)
Gitlab::ExclusiveLease.cancel(LEASE_KEY, lease_uuid)
ids
end
end