Skip to content

feat: add QuotaUsed/QuotaResetAt to Provider for restart persistence#63

Merged
javi11 merged 1 commit intomainfrom
feat/quota-restart-persistence
Apr 11, 2026
Merged

feat: add QuotaUsed/QuotaResetAt to Provider for restart persistence#63
javi11 merged 1 commit intomainfrom
feat/quota-restart-persistence

Conversation

@javi11
Copy link
Copy Markdown
Owner

@javi11 javi11 commented Apr 11, 2026

Summary

  • Adds QuotaUsed int64 and QuotaResetAt time.Time fields to Provider so callers can restore quota state across application restarts
  • On group init, if QuotaUsed > 0 it is applied to the atomic counter and quotaExceeded is set if already at the limit; if QuotaResetAt is in the future it overrides the default reset deadline
  • No library-side persistence: callers read Stats() before shutdown and pass the values back on the next run — zero overhead, zero interface to implement

Test plan

  • go test -race -run Quota ./... passes
  • go build ./... clean
  • Verify on restart: set QuotaUsed to a value below the limit and confirm downloads continue; set it at/above the limit and confirm ErrQuotaExceeded is returned immediately
  • Verify QuotaResetAt in the past falls back to a fresh now + QuotaPeriod deadline

Quota state (bytes consumed and period reset deadline) is now exposed
via ProviderStats and can be restored on restart by setting QuotaUsed
and QuotaResetAt on the Provider config. No library-side persistence is
needed — callers read Stats() before shutdown and pass the values back
on the next run.

Also rewrote README with comprehensive examples, expanded API reference,
and a dedicated quota management section showing the save/restore pattern.
@javi11 javi11 merged commit db906b0 into main Apr 11, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant