Class: Kaal::IdempotencyKeyGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/kaal/idempotency_key_generator.rb

Overview

Utility class for generating idempotency keys.

Centralizes the key format to prevent drift between public API and internal coordinator. Format: namespace-cron_key-fire_time_unix

Examples:

Generate a key

key = Kaal::IdempotencyKeyGenerator.call('reports:daily', Time.current, configuration: config)
# => "kaal-reports:daily-1708283400"

Class Method Summary collapse

Class Method Details

.call(cron_key, fire_time, configuration:) ⇒ String

Generate an idempotency key for a cron job.

Parameters:

  • cron_key (String)

    the cron job key

  • fire_time (Time)

    the fire time

  • configuration (Configuration)

    the Kaal configuration instance

Returns:

  • (String)

    the formatted idempotency key



26
27
28
29
# File 'lib/kaal/idempotency_key_generator.rb', line 26

def self.call(cron_key, fire_time, configuration:)
  namespace = configuration.namespace || 'kaal'
  "#{namespace}-#{cron_key}-#{fire_time.to_i}"
end