Async LimiterSourceAsyncLimiterTimingFixedWindow

class FixedWindow

Fixed window timing strategy with discrete boundaries aligned to clock time.

Fixed windows reset at specific intervals (e.g., every minute at :00 seconds), creating predictable timing patterns and allowing bursting at window boundaries.

Definitions

def window_start_time(current_time)

Calculate the start time of the fixed window containing the given time.

Signature

parameter current_time Numeric

The current time.

returns Numeric

The window start time aligned to window boundaries.

Implementation

def window_start_time(current_time)
	(current_time / @duration).to_i * @duration
end

def statistics

Get current timing strategy statistics.

Signature

returns Hash

Statistics hash with current state.

Implementation

def statistics
	current_time = Time.now
	
	{
		name: "FixedWindow",
		window_duration: @duration,
		window_limit: @limit,
		current_window_count: @window_count,
		window_utilization_percentage: (@window_count.to_f / @limit) * 100,
		burst: @burst.statistics,
	}
end