Skip to content

feat(config): support ActiveSupport::Duration for lock_ttl#934

Merged
mhenrixon merged 1 commit intomainfrom
issue-908-duration-lock-ttl
Mar 27, 2026
Merged

feat(config): support ActiveSupport::Duration for lock_ttl#934
mhenrixon merged 1 commit intomainfrom
issue-908-duration-lock-ttl

Conversation

@mhenrixon
Copy link
Copy Markdown
Owner

@mhenrixon mhenrixon commented Mar 27, 2026

Closes #892

Summary

  • LockTTL#calculate_timing raised ArgumentError for ActiveSupport::Duration because it's not a Numeric subclass
  • Now accepts any object responding to #to_i, which supports ActiveSupport::Duration and similar duration-like objects
  • Invalid types (like Range) that don't respond to #to_i still raise ArgumentError

Closes #908

Test plan

  • New test: duration-like object with #to_i is coerced correctly
  • Existing test: Range still raises ArgumentError
  • Full suite: 1051 examples, 0 failures
  • Rubocop: 282 files, no offenses

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 27, 2026

Warning

Rate limit exceeded

@mhenrixon has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 0 minutes and 4 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 0 minutes and 4 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2408ec45-402e-4fd0-9676-673cde83724a

📥 Commits

Reviewing files that changed from the base of the PR and between 1b7c5fd and 09e16ae.

📒 Files selected for processing (2)
  • lib/sidekiq_unique_jobs/lock_ttl.rb
  • spec/sidekiq_unique_jobs/lock_ttl_spec.rb
📝 Walkthrough

Walkthrough

The change adds duck-typing support to LockTTL#calculate_timing to accept duration-like objects. Instead of immediately raising an error for unsupported types, the code now checks if the object responds to to_i and uses that method for coercion before raising an ArgumentError.

Changes

Cohort / File(s) Summary
Lock TTL Type Coercion
lib/sidekiq_unique_jobs/lock_ttl.rb
Added respond_to?(:to_i) check in the error branch to enable duck-typing support for duration-like objects that implement integer coercion.
Type Coercion Tests
spec/sidekiq_unique_jobs/lock_ttl_spec.rb
Added test context for #calculate with custom duration-like objects responding to #to_i, verifying successful coercion to integer values.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A duck-typed duration hops with glee,
No more errors for to_i!
Seconds and minutes now align,
Making lock configs simply divine.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding support for ActiveSupport::Duration objects in the lock_ttl configuration option.
Linked Issues check ✅ Passed The PR fully implements the requirement from issue #908 by accepting objects responding to #to_i for lock_ttl, enabling ActiveSupport::Duration support while preserving validation for unsupported types.
Out of Scope Changes check ✅ Passed All changes are strictly scoped to implementing duration-like object support for lock_ttl; no unrelated modifications or scope creep detected in the production code or tests.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@mhenrixon mhenrixon self-assigned this Mar 27, 2026
LockTTL#calculate_timing raised ArgumentError for any type not in its
explicit case branches (String, Numeric, Proc, Symbol). Since
ActiveSupport::Duration is not a Numeric subclass, using
`lock_ttl: 10.seconds` in sidekiq_options raised an error.

Now any object responding to #to_i is accepted as a valid lock_ttl value,
which supports ActiveSupport::Duration and other duration-like objects.

Closes #908
@mhenrixon mhenrixon force-pushed the issue-908-duration-lock-ttl branch from 1b7c5fd to 09e16ae Compare March 27, 2026 23:28
@mhenrixon mhenrixon enabled auto-merge (squash) March 27, 2026 23:28
@mhenrixon mhenrixon merged commit f302296 into main Mar 27, 2026
32 checks passed
@mhenrixon mhenrixon deleted the issue-908-duration-lock-ttl branch March 27, 2026 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support ActiveSupport::Duration for lock_ttl option

1 participant