f93f8f569d
Enables frozen string for the following: * lib/gitlab/patch/**/*.rb * lib/gitlab/popen/**/*.rb * lib/gitlab/profiler/**/*.rb * lib/gitlab/project_authorizations/**/*.rb * lib/gitlab/prometheus/**/*.rb * lib/gitlab/query_limiting/**/*.rb * lib/gitlab/quick_actions/**/*.rb * lib/gitlab/redis/**/*.rb * lib/gitlab/request_profiler/**/*.rb * lib/gitlab/search/**/*.rb * lib/gitlab/sherlock/**/*.rb * lib/gitlab/sidekiq_middleware/**/*.rb * lib/gitlab/slash_commands/**/*.rb * lib/gitlab/sql/**/*.rb * lib/gitlab/template/**/*.rb * lib/gitlab/testing/**/*.rb * lib/gitlab/utils/**/*.rb * lib/gitlab/webpack/**/*.rb Partially addresses gitlab-org/gitlab-ce#47424.
51 lines
1 KiB
Ruby
51 lines
1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Gitlab
|
|
module Sherlock
|
|
# A collection of transactions recorded by Sherlock.
|
|
#
|
|
# Method calls for this class are synchronized using a mutex to allow
|
|
# sharing of a single Collection instance between threads (e.g. when using
|
|
# Puma as a webserver).
|
|
class Collection
|
|
include Enumerable
|
|
|
|
def initialize
|
|
@transactions = []
|
|
@mutex = Mutex.new
|
|
end
|
|
|
|
def add(transaction)
|
|
synchronize { @transactions << transaction }
|
|
end
|
|
|
|
alias_method :<<, :add
|
|
|
|
def each(&block)
|
|
synchronize { @transactions.each(&block) }
|
|
end
|
|
|
|
def clear
|
|
synchronize { @transactions.clear }
|
|
end
|
|
|
|
def empty?
|
|
synchronize { @transactions.empty? }
|
|
end
|
|
|
|
def find_transaction(id)
|
|
find { |trans| trans.id == id }
|
|
end
|
|
|
|
def newest_first
|
|
sort { |a, b| b.finished_at <=> a.finished_at }
|
|
end
|
|
|
|
private
|
|
|
|
def synchronize(&block)
|
|
@mutex.synchronize(&block)
|
|
end
|
|
end
|
|
end
|
|
end
|