Skip to content

[worker] tokens cleanup#234

Merged
capcom6 merged 1 commit into
masterfrom
worker/tokens-cleanup
Jun 2, 2026
Merged

[worker] tokens cleanup#234
capcom6 merged 1 commit into
masterfrom
worker/tokens-cleanup

Conversation

@capcom6

@capcom6 capcom6 commented May 26, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features
    • Automatic token cleanup that periodically removes expired tokens; logs count of removed entries.
    • Configurable cleanup interval and grace period via env vars or config (TASKS__TOKENS_CLEANUP__INTERVAL default 24h, TASKS__TOKENS_CLEANUP__MAX_AGE default 1h).

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 26, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a794f916-0c63-4368-96ec-e4e15ae7bd6c

📥 Commits

Reviewing files that changed from the base of the PR and between 8e7f866 and 001afeb.

📒 Files selected for processing (9)
  • .env.example
  • configs/config.example.yml
  • internal/sms-gateway/jwt/repository.go
  • internal/worker/config/config.go
  • internal/worker/config/module.go
  • internal/worker/tasks/module.go
  • internal/worker/tasks/tokens/cleanup.go
  • internal/worker/tasks/tokens/config.go
  • internal/worker/tasks/tokens/module.go
✅ Files skipped from review due to trivial changes (1)
  • internal/worker/tasks/module.go
🚧 Files skipped from review as they are similar to previous changes (7)
  • configs/config.example.yml
  • internal/worker/tasks/tokens/config.go
  • .env.example
  • internal/sms-gateway/jwt/repository.go
  • internal/worker/config/module.go
  • internal/worker/config/config.go
  • internal/worker/tasks/tokens/cleanup.go

📝 Walkthrough

Walkthrough

This PR adds a periodic worker task that deletes expired JWT tokens. It introduces env/YAML configuration and worker config structs for interval and max-age, adds a repository Cleanup method to remove expired token rows, implements a periodic cleanup task, and wires the config, repo, and task into the Fx modules.

Changes

Token Cleanup Worker Task

Layer / File(s) Summary
Configuration Schema and Examples
.env.example, configs/config.example.yml, internal/worker/config/config.go
Adds TASKS__TOKENS_CLEANUP__INTERVAL and TASKS__TOKENS_CLEANUP__MAX_AGE examples, tasks.tokens_cleanup YAML, a TokensCleanup config struct and field on Tasks, and default interval/max_age values.
Config Dependency Injection
internal/worker/config/module.go
Worker config module provides tokens.Config by converting cfg.Tasks.TokensCleanup interval and max-age to time.Duration.
Token Repository Cleanup Method
internal/sms-gateway/jwt/repository.go
Adds Cleanup(ctx, before) to delete tokenModel rows with expires_at < before and return the deleted row count.
Token Cleanup Task Definition
internal/worker/tasks/tokens/config.go, internal/worker/tasks/tokens/cleanup.go
Defines CleanupConfig with Interval and MaxAge. Implements cleanupTask as executor.PeriodicTask that computes cutoff (now - MaxAge), calls repository Cleanup, wraps errors, and logs non-zero cleaned row counts.
Token Cleanup Task Wiring
internal/worker/tasks/tokens/module.go, internal/worker/tasks/module.go
Adds tokens Fx module: named logger, provides CleanupConfig, registers JWT repository and cleanup task via executor.AsWorkerTask(), and registers tokens.Module() in the tasks module.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[worker] tokens cleanup' directly and clearly summarizes the main change: adding a tokens cleanup feature to the worker component.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions

github-actions Bot commented May 26, 2026

Copy link
Copy Markdown

🤖 Pull request artifacts

Platform File
🐳 Docker GitHub Container Registry
🍎 Darwin arm64 server_Darwin_arm64.tar.gz
🍎 Darwin x86_64 server_Darwin_x86_64.tar.gz
🐧 Linux arm64 server_Linux_arm64.tar.gz
🐧 Linux i386 server_Linux_i386.tar.gz
🐧 Linux x86_64 server_Linux_x86_64.tar.gz
🪟 Windows arm64 server_Windows_arm64.zip
🪟 Windows i386 server_Windows_i386.zip
🪟 Windows x86_64 server_Windows_x86_64.zip

@capcom6 capcom6 added the ready label May 26, 2026
@capcom6 capcom6 force-pushed the worker/tokens-cleanup branch from 8e7f866 to e1db66a Compare May 28, 2026 03:02
@github-actions github-actions Bot removed the ready label May 28, 2026
@capcom6 capcom6 added the ready label May 28, 2026
@capcom6 capcom6 force-pushed the worker/tokens-cleanup branch from e1db66a to 001afeb Compare May 30, 2026 01:13
@github-actions github-actions Bot removed the ready label May 30, 2026
@capcom6 capcom6 added ready deployed The PR is deployed on staging labels May 30, 2026
@capcom6 capcom6 merged commit 7c53a73 into master Jun 2, 2026
11 checks passed
@capcom6 capcom6 deleted the worker/tokens-cleanup branch June 2, 2026 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deployed The PR is deployed on staging ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant