mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-28 07:57:45 +00:00
634fc631b3
This is a first step to have something concrete to discuss. Needs tuning and tests.
27 lines
834 B
Ruby
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
|