mastodon/app/workers/concerns/low_priority_scheduler.rb
David Roetzel 634fc631b3
Add scheduled job to clean up old notficiations.
This is a first step to have something concrete to discuss.

Needs tuning and tests.
2024-08-01 13:59:21 +02:00

27 lines
834 B
Ruby

# frozen_string_literal: true
module LowPriorityScheduler
# These are latency limits on various queues above which a server is
# considered to be under load, causing the auto-deletion to be entirely
# skipped for that run.
LOAD_LATENCY_THRESHOLDS = {
default: 5,
push: 10,
# The `pull` queue has lower priority jobs, and it's unlikely that
# pushing deletes would cause much issues with this queue if it didn't
# cause issues with `default` and `push`. Yet, do not enqueue deletes
# if the instance is lagging behind too much.
pull: 5.minutes.to_i,
}.freeze
def under_load?
LOAD_LATENCY_THRESHOLDS.any? { |queue, max_latency| queue_under_load?(queue, max_latency) }
end
private
def queue_under_load?(name, max_latency)
Sidekiq::Queue.new(name).latency > max_latency
end
end