Class: CommandTower::Services::Account::Push::CheckSelfTestRateLimit
- Inherits:
-
CommandTower::Services::ApplicationService
- Object
- CommandTower::ServiceBase
- CommandTower::Services::ApplicationService
- CommandTower::Services::Account::Push::CheckSelfTestRateLimit
- Defined in:
- app/services/command_tower/services/account/push/check_self_test_rate_limit.rb
Overview
Enforces Me push self-test rate limits via existing RateLimits::Check. Ceiling and window come from config.messaging.expo composers — not hardcoded here.
Constant Summary
Constants inherited from CommandTower::ServiceBase
CommandTower::ServiceBase::ON_ARGUMENT_VALIDATION
Instance Method Summary collapse
Methods inherited from CommandTower::Services::ApplicationService
Methods included from Transactional
#fail_transaction!, #transaction
Methods inherited from CommandTower::ServiceBase
#command_tower_lifecycle, inherited, #internal_validate, #service_lifecycle_error_codes, #service_lifecycle_log_level, #validate!
Methods included from Logging::LifecycleDeclaration
Methods included from Execution::ContextAccess
#audit, #execution_context, #log_debug, #log_error, #log_info, #log_warn, #publish_event
Methods included from ArgumentValidation
Methods included from CommandTower::ServiceLogging
Instance Method Details
#call ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/services/command_tower/services/account/push/check_self_test_rate_limit.rb', line 12 def call expo = CommandTower.config.messaging.expo limit = expo.self_test_per_user_hour ttl_seconds = expo.self_test_window_seconds result = CommandTower::Services::RateLimits::Check.call( key: "me:push:self_test:user:#{user.id}", ttl_seconds:, ) if result.failure? context.fail!(application_error: result.errors.first) return end count = result.data[:count] return if count <= limit ttl = result.data[:ttl] retry_after = ttl.positive? ? ttl : nil context.fail!( application_error: CommandTower::Errors::Account::PushTestRateLimitError.new( retry_after_seconds: retry_after, ), ) end |