Class: Cosmos::SlowQueryTrackerWorker

Inherits:
ApplicationWorker show all
Includes:
ElasticAPM::SpanHelpers
Defined in:
app/workers/cosmos/slow_query_tracker_worker.rb

Instance Method Summary collapse

Methods inherited from ApplicationWorker

unlimited_retry

Instance Method Details

#perform(payload_sql, payload_name, duration, backtrace) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'app/workers/cosmos/slow_query_tracker_worker.rb', line 5

def perform(payload_sql, payload_name, duration, backtrace)
  # Use Rails cache to deduplicate within 5 minutes
  sql_hash = Digest::MD5.hexdigest(payload_sql)
  cache_key = "slow_query_tracker:#{sql_hash}"

  # Skip if we've already processed this query recently
  Rails.cache.fetch(cache_key, expires_in: 5.minutes) do
    analyze_slow_query(payload_sql, payload_name, duration, backtrace)
    true # Store something in cache to mark as processed
  end
end