Skip to content

Clean up successful and failed jobs #343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 11, 2025
Merged

Clean up successful and failed jobs #343

merged 3 commits into from
Jun 11, 2025

Conversation

msukkari
Copy link
Contributor

@msukkari msukkari commented Jun 10, 2025

Fixes memory leak in redis

Summary by CodeRabbit

  • New Features
    • Added configuration options to control retention of completed and failed jobs in Redis queues via new environment variables.
  • Documentation
    • Updated documentation to describe new environment variables for Redis job retention.
    • Updated changelog with details about Redis job cleanup.
  • Chores
    • Added optional environment variables for Logtail integration.
  • Style
    • Removed unnecessary logging when defaulting to the "oss" plan for entitlements.

@msukkari msukkari requested a review from brendan-kellam June 10, 2025 23:49
Copy link

coderabbitai bot commented Jun 10, 2025

Walkthrough

This update introduces new environment variables to control job retention in Redis queues, modifies backend job scheduling to respect these settings, and updates related documentation. Additional optional logging environment variables are added on the web side. A redundant log message is removed from the entitlements server, and the changelog is updated accordingly.

Changes

File(s) Change Summary
CHANGELOG.md Updated to document Redis job cleanup feature under "Unreleased".
docs/docs/configuration/environment-variables.mdx Added documentation for REDIS_REMOVE_ON_COMPLETE and REDIS_REMOVE_ON_FAIL environment variables.
packages/backend/src/env.ts Added REDIS_REMOVE_ON_COMPLETE and REDIS_REMOVE_ON_FAIL to backend environment schema.
packages/backend/src/connectionManager.ts,
packages/backend/src/repoManager.ts
Jobs added to Redis queues now use removeOnComplete and removeOnFail options from environment variables.
packages/web/src/env.mjs Added optional LOGTAIL_TOKEN and LOGTAIL_HOST environment variables.
packages/web/src/features/entitlements/server.ts Removed a log statement for missing license key; no change to logic or return value.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Backend
    participant RedisQueue

    User->>Backend: Trigger job scheduling (e.g., sync, index, GC)
    Backend->>RedisQueue: Add job with options (removeOnComplete, removeOnFail) from env
    RedisQueue-->>Backend: Job processed, cleanup according to settings
Loading

Poem

In the warren where jobs hop and leap,
New rules decide which ones to keep.
Some are swept when they’re done or fail,
Guided by settings in an env detail.
The changelog’s updated, the docs are too—
A tidier queue for me and you!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8866135 and 0fa8ae0.

📒 Files selected for processing (1)
  • packages/backend/src/env.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/backend/src/env.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: check-links
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
CHANGELOG.md (1)

16-16: Consider re-wording the bullet for clarity

The phrase “Clean up successful and failed jobs in Redis queues” is clear, but readers might more easily associate the fix with the original issue if you explicitly mention the memory-leak symptom, e.g. “Prevent Redis memory leak by cleaning up completed/failed jobs”.
Optional, purely editorial.

packages/web/src/env.mjs (1)

70-72: Missing docs entry for new LOGTAIL variables

LOGTAIL_TOKEN and LOGTAIL_HOST are now part of the runtime schema, but the environment-variables reference page wasn’t updated in this PR. Please add them so users know how to configure centralised logging.

docs/docs/configuration/environment-variables.mdx (1)

26-27: Good addition – consider clarifying semantics

You might add “0 removes jobs immediately” and “n > 0 retains the most-recent n jobs” so users understand the numeric meaning without referring to BullMQ docs.

packages/backend/src/repoManager.ts (1)

402-405: Apply custom job retention settings to garbage collection queue
This mirrors the index-queue changes by automatically removing completed/failed GC jobs per configuration. To reduce duplication, consider extracting the removeOnComplete/removeOnFail options into a shared constant or helper.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9be5522 and 8866135.

📒 Files selected for processing (7)
  • CHANGELOG.md (1 hunks)
  • docs/docs/configuration/environment-variables.mdx (1 hunks)
  • packages/backend/src/connectionManager.ts (1 hunks)
  • packages/backend/src/env.ts (1 hunks)
  • packages/backend/src/repoManager.ts (3 hunks)
  • packages/web/src/env.mjs (1 hunks)
  • packages/web/src/features/entitlements/server.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/web/src/features/entitlements/server.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/backend/src/connectionManager.ts (1)
packages/backend/src/env.ts (1)
  • env (22-55)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (3)
packages/backend/src/connectionManager.ts (1)

68-70: Verify runtime values are numeric after the env fix

removeOnComplete / removeOnFail expect boolean | number | {count|age}.
After changing the schema to numberSchema, env.REDIS_REMOVE_ON_COMPLETE will be a number, but if the variables are unset they’ll default to 0 & 100, which is fine.

Once the schema fix lands, this block is good.
No action needed here other than re-running locally to ensure startup succeeds.

packages/backend/src/repoManager.ts (2)

13-13: Add import for env configuration
This import enables use of the new Redis cleanup environment variables (REDIS_REMOVE_ON_COMPLETE and REDIS_REMOVE_ON_FAIL) in job scheduling.


110-113:

❓ Verification inconclusive

Apply custom job retention settings to index queue
Ensure that env.REDIS_REMOVE_ON_COMPLETE and env.REDIS_REMOVE_ON_FAIL are parsed as the correct types (number | boolean) required by BullMQ, and verify that their default values (0 and 100) fulfill your memory-leak mitigation and debugging needs.


🏁 Script executed:

#!/bin/bash
# Verify type and default values for retention variables in env.ts
rg -n "REDIS_REMOVE_ON_COMPLETE" packages/backend/src/env.ts
rg -n "REDIS_REMOVE_ON_FAIL" packages/backend/src/env.ts

Length of output: 235


Apply custom job retention settings to index queue – variables verified

  • In packages/backend/src/env.ts (lines 38–39),
    REDIS_REMOVE_ON_COMPLETE is defined as z.number().default(0)
    REDIS_REMOVE_ON_FAIL is defined as z.number().default(100)
  • These values satisfy BullMQ’s number requirement.
  • If you also need to support boolean flags (e.g. keep all jobs when true), consider using a preprocess/coerce schema (e.g. z.preprocess or z.coerce.boolean()) or adjust the types accordingly.
  • Confirm that retaining 0 completed jobs and up to 100 failed jobs aligns with your memory-leak mitigation and debugging strategy.

Copy link

brendan-kellam
brendan-kellam previously approved these changes Jun 10, 2025
@msukkari msukkari merged commit 1ea377e into main Jun 11, 2025
6 checks 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.

2 participants