Skip to content

Create dedicated alerts worker #2184

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 2 commits into from
Jun 19, 2025
Merged

Conversation

ericallam
Copy link
Member

No description provided.

Copy link

changeset-bot bot commented Jun 19, 2025

⚠️ No Changeset found

Latest commit: 9b9e736

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Jun 19, 2025

Walkthrough

This change introduces a dedicated alerts worker system to the application. It adds a new environment variable schema for configuring the alerts worker, including concurrency, polling, shutdown, and Redis connection settings. A new alertsWorker.server.ts file is created to define and initialize the alerts worker, which registers and handles alert-related jobs using environment-driven configuration. Alert service classes are updated to enqueue jobs via the new alerts worker instead of the common worker. Comments and import statements are updated to reflect the migration of alert jobs to the new worker. Additionally, a debug log is added to the batch task run completion function, and the enqueue logic for batch run resumption is updated to allow transactional enqueuing.


📜 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 3c93783 and 9b9e736.

📒 Files selected for processing (11)
  • apps/webapp/app/env.server.ts (1 hunks)
  • apps/webapp/app/services/worker.server.ts (5 hunks)
  • apps/webapp/app/v3/alertsWorker.server.ts (1 hunks)
  • apps/webapp/app/v3/commonWorker.server.ts (1 hunks)
  • apps/webapp/app/v3/services/alerts/deliverAlert.server.ts (2 hunks)
  • apps/webapp/app/v3/services/alerts/performDeploymentAlerts.server.ts (2 hunks)
  • apps/webapp/app/v3/services/alerts/performTaskRunAlerts.server.ts (2 hunks)
  • apps/webapp/app/v3/services/batchTriggerV3.server.ts (1 hunks)
  • apps/webapp/app/v3/services/createCheckpoint.server.ts (1 hunks)
  • apps/webapp/app/v3/services/finalizeTaskRun.server.ts (1 hunks)
  • apps/webapp/app/v3/services/resumeBatchRun.server.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (25)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (9, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (7, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (6, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (8, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (10, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (1, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (5, 10)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (3, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (2, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (4, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (3, 10)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (4, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (5, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (8, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (7, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (6, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (1, 8)
  • GitHub Check: units / packages / 🧪 Unit Tests: Packages (1, 1)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (2, 8)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (24)
apps/webapp/app/v3/services/createCheckpoint.server.ts (1)

395-395: LGTM! Correctly updated to match new method signature.

The removal of the Prisma client argument aligns with the updated ResumeBatchRunService.enqueue method signature where the transaction parameter is now optional.

apps/webapp/app/v3/services/alerts/performDeploymentAlerts.server.ts (2)

2-2: LGTM! Correct migration to dedicated alerts worker.

The import change from commonWorker to alertsWorker properly supports the dedicated alerts worker architecture.


60-60: LGTM! Consistent with alerts worker migration.

The enqueue call correctly uses the new alertsWorker instead of commonWorker, maintaining the same job structure and payload.

apps/webapp/app/v3/services/batchTriggerV3.server.ts (1)

945-952: LGTM! Excellent observability improvement.

The debug logging provides comprehensive visibility into the batch task run completion workflow, which will be valuable for troubleshooting and monitoring.

apps/webapp/app/v3/commonWorker.server.ts (3)

240-240: LGTM! Proper deprecation documentation.

The deprecation comment clearly indicates the migration to alertsWorker.server.ts while maintaining backward compatibility.


246-246: LGTM! Consistent deprecation pattern.

Following the same deprecation pattern as other alert handlers, properly documenting the migration path.


252-252: LGTM! Complete deprecation coverage.

All alert-related handlers are now properly deprecated with consistent documentation of the migration to the alerts worker.

apps/webapp/app/v3/services/finalizeTaskRun.server.ts (1)

247-247: LGTM! Consistent with updated method signature.

The removal of the Prisma client argument correctly aligns with the updated ResumeBatchRunService.enqueue method where the transaction parameter is now optional.

apps/webapp/app/v3/services/alerts/performTaskRunAlerts.server.ts (2)

3-3: LGTM: Import updated for dedicated alerts worker.

The import change aligns with the introduction of the dedicated alerts worker system.


65-70: ```bash
#!/usr/bin/env bash
set -euo pipefail

echo "=== Finding alertsWorker.server.ts ==="
fd -t f "alertsWorker.server.ts" || true
ALERTS_PATH=$(fd -t f "alertsWorker.server.ts" | head -n1 || true)

if [[ -n "$ALERTS_PATH" ]]; then
echo "=== Showing top of $ALERTS_PATH ==="
sed -n '1,200p' "$ALERTS_PATH"
echo
echo "=== Enqueue signature in alertsWorker ==="
rg -n "enqueue" -C3 "$ALERTS_PATH" || true
else
echo "⚠️ alertsWorker.server.ts not found"
fi

echo
echo "=== Finding commonWorker.server.ts ==="
fd -t f "commonWorker.server.ts" || true
COMMON_PATH=$(fd -t f "commonWorker.server.ts" | head -n1 || true)

if [[ -n "$COMMON_PATH" ]]; then
echo "=== Showing top of $COMMON_PATH ==="
sed -n '1,200p' "$COMMON_PATH"
echo
echo "=== Enqueue signature in commonWorker ==="
rg -n "enqueue" -C3 "$COMMON_PATH" || true
else
echo "⚠️ commonWorker.server.ts not found"
fi


</details>
<details>
<summary>apps/webapp/app/v3/services/alerts/deliverAlert.server.ts (2)</summary>

`14-42`: **Import reorganization looks clean.**

The reordering of imports improves code organization without affecting functionality.

---

`1046-1051`: **LGTM: Migration to alerts worker.**

The enqueue method correctly migrates to use the dedicated alerts worker, maintaining the same interface pattern.

</details>
<details>
<summary>apps/webapp/app/services/worker.server.ts (2)</summary>

`36-36`: **Good documentation update.**

The clarification about `v3.resumeBatchRun` being deprecated but still used in transactions is helpful.

---

`167-167`: **LGTM: Clear deprecation notices.**

The updated comments clearly indicate that alert-related tasks have been moved to `alertsWorker.server.ts`, which helps with code maintenance and understanding.



Also applies to: 218-218, 227-227, 237-237

</details>
<details>
<summary>apps/webapp/app/v3/services/resumeBatchRun.server.ts (3)</summary>

`7-7`: **Import addition looks correct.**

Adding the `workerQueue` import is necessary for the new conditional enqueuing logic.

---

`335-335`: **Good: Making transaction parameter optional maintains backward compatibility.**

The optional `tx` parameter ensures existing callers continue to work without modification.

---

`338-371`: **Review the conditional enqueuing logic for interface compatibility.**

The conditional logic looks reasonable, but verify that both `workerQueue.enqueue` and `commonWorker.enqueue` handle the job parameters consistently.



```shell
#!/bin/bash
# Description: Check if workerQueue and commonWorker have compatible enqueue interfaces
# Expected: Both should handle the same job type and parameters properly

echo "=== Checking workerQueue enqueue interface ==="
ast-grep --pattern 'workerQueue.enqueue($_, $_, $_)'

echo "=== Checking commonWorker enqueue interface ==="
ast-grep --pattern 'commonWorker.enqueue($_)'

echo "=== Checking resumeBatchRun job handlers ==="
rg -A 5 "v3\.resumeBatchRun" --type ts
apps/webapp/app/v3/alertsWorker.server.ts (6)

12-21: Redis configuration looks comprehensive.

The Redis configuration includes all necessary options including TLS handling and authentication. The conditional TLS configuration based on ALERTS_WORKER_REDIS_TLS_DISABLED is a good pattern.


27-55: Job catalog schema definitions are consistent.

The job schemas match the expected payloads used by the alert services. The retry configuration and visibility timeouts are reasonable for alert processing.


65-81: Job handlers are correctly implemented.

The job handlers properly instantiate the corresponding service classes and call their call methods with the appropriate payload parameters.


83-92: Good: Conditional worker startup with comprehensive logging.

The conditional startup based on ALERTS_WORKER_ENABLED allows for flexible deployment, and the debug logging provides good visibility into worker configuration.


94-94: Singleton pattern usage is appropriate.

Using the singleton pattern ensures a single worker instance across the application, which is correct for this use case.


56-64: Verify environment variables are properly defined.

The worker uses many new environment variables for configuration. Ensure all these variables are defined in the environment schema.

#!/bin/bash
# Description: Check if all ALERTS_WORKER environment variables are defined
# Expected: All variables should be defined in env.server.ts

echo "=== Checking for ALERTS_WORKER environment variables in env.server.ts ==="
rg "ALERTS_WORKER" apps/webapp/app/env.server.ts

echo "=== Checking for any missing ALERTS_WORKER variables ==="
rg "ALERTS_WORKER_[A-Z_]+" apps/webapp/app/v3/alertsWorker.server.ts | sort | uniq
apps/webapp/app/env.server.ts (1)

695-732: LGTM! Well-structured alerts worker configuration.

The alerts worker environment variables are implemented consistently with the established patterns in the codebase. The configuration follows the same structure as other worker systems (COMMON_WORKER, SCHEDULE_WORKER), uses appropriate fallback mechanisms for Redis settings, and includes sensible default values.

Key strengths:

  • Consistent naming convention with ALERTS_WORKER_ prefix
  • Proper Redis fallback to base REDIS_* environment variables
  • Appropriate validation with correct Zod types
  • Reasonable default values aligned with other worker configurations
✨ 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.

@ericallam ericallam merged commit f2db1b8 into main Jun 19, 2025
59 of 61 checks passed
@ericallam ericallam deleted the worker-resilience-improvements branch June 19, 2025 10:54
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