Skip to content

refactor(worker): remove organization existence check from workflow worker fixes NV-7910#11357

Merged
scopsy merged 1 commit into
nextfrom
cursor/remove-workflow-org-exist-query-458b
May 29, 2026
Merged

refactor(worker): remove organization existence check from workflow worker fixes NV-7910#11357
scopsy merged 1 commit into
nextfrom
cursor/remove-workflow-org-exist-query-458b

Conversation

@scopsy
Copy link
Copy Markdown
Contributor

@scopsy scopsy commented May 29, 2026

Summary

Removes the redundant organizationExist MongoDB lookup from the workflow worker job processor. Trigger jobs no longer skip processing when the organization document is missing at this stage.

Changes

  • Removed the pre-processing organization existence check and early return in WorkflowWorker
  • Removed the private organizationExist helper and CommunityOrganizationRepository dependency
  • Updated workflow.worker.spec.ts constructor call to match the new signature

Why

The organization existence query is no longer needed before processing workflow trigger jobs.

Testing

  • Verified changed files pass Biome check
  • No behavior change expected beyond removing the skip-on-missing-org path
Open in Web Open in Cursor 

Greptile Summary

This PR removes the organizationExist MongoDB lookup and early-return guard from WorkflowWorker, eliminating the CommunityOrganizationRepository dependency from the constructor entirely. The intent is to treat any downstream failure (including a missing org) as a non-retryable error handled by the existing at-most-once setSqsFailedHandler, rather than a pre-checked silent skip.

  • workflow.worker.ts: Drops CommunityOrganizationRepository import/injection, removes the org-existence guard and its helper method. Jobs that previously silently acked on a missing org now proceed to triggerEventUsecase.execute().
  • workflow.worker.spec.ts: Updates the WorkflowWorker constructor call to the new 5-argument signature. mockOrganizationRepository and the CommunityOrganizationRepository import are intentionally kept since WorkflowQueueService still requires them.

Confidence Score: 4/5

Safe to merge; the refactor is minimal and intentional, with the main trade-off being that jobs for missing organizations now fail loudly rather than being silently skipped.

The deletion is clean and self-contained. The key behavioral shift is that a job whose organization no longer exists will now reach triggerEventUsecase.execute() and, if it throws, be permanently dropped by the at-most-once setSqsFailedHandler rather than silently skipped upfront. Whether this is fully safe depends on whether the use-case handles a missing org gracefully — that path is not exercised by the updated tests.

workflow.worker.spec.ts has no test covering the scenario where triggerEventUsecase.execute is called with a non-existent organization, so the new error path is untested.

Important Files Changed

Filename Overview
apps/worker/src/app/workflow/services/workflow.worker.ts Removes CommunityOrganizationRepository dependency, org-existence pre-check, and helper method. Clean deletion; the behavioral change (missing-org jobs now reach the use-case instead of being silently skipped) is intentional per the PR description.
apps/worker/src/app/workflow/services/workflow.worker.spec.ts Constructor call updated to match new 5-argument signature. mockOrganizationRepository and CommunityOrganizationRepository import are correctly retained for WorkflowQueueService usage.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[SQS / BullMQ Job Received] --> B{Kill switch enabled?}
    B -- Yes --> C[Log warn, skip job]
    B -- No --> D[triggerEventUsecase.execute]
    D -- Success --> E[Job acked / complete]
    D -- Throws --> F[setSqsFailedHandler]
    F --> G[Log warning, drop job at-most-once]
    style C fill:#ffd700,color:#000
    style G fill:#ff6b6b,color:#fff
    subgraph REMOVED [Removed in this PR]
        R1{organizationExist?}
        R2[Log warn, skip job]
        R1 -- No --> R2
    end
Loading

Fix All in Cursor

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
apps/worker/src/app/workflow/services/workflow.worker.ts:93-119
**Missing-org path now silently drops jobs without a dedicated test**

Previously, a missing organization caused an explicit early return with a clear log message. Now, if `triggerEventUsecase.execute(data)` throws because the organization doesn't exist, the job is swallowed by `setSqsFailedHandler` and permanently dropped (at-most-once). The spec has no test for this failure path — if the use-case doesn't handle a missing org gracefully and throws an unexpected error type, the failure will be invisible beyond the generic `setSqsFailedHandler` warning. Worth adding a test that stubs `triggerEventUsecase.execute` to throw and verifies the job is dropped (not retried).

Reviews (1): Last reviewed commit: "refactor(worker): remove organization ex..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

What changed

The PR removes a redundant organization existence check from the workflow worker job processor. Previously, the worker would skip processing trigger jobs if the organization document wasn't found in MongoDB. This check has been eliminated along with the organizationRepository dependency, allowing jobs to proceed directly to execution after the kill-switch check.

Affected areas

  • worker: Removed the organizationRepository dependency and organizationExist method from WorkflowWorker, eliminating the pre-processing organization check that was skipping job execution when the organization was missing.

Testing

The test file was updated to match the new WorkflowWorker constructor signature. Existing test logic for queue draining and worker lifecycle assertions remains unchanged. The PR was verified to pass Biome checks.

Review Change Stack

…orker

Co-authored-by: Dima Grossman <dima@grossman.io>
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 29, 2026

NV-7910

@netlify
Copy link
Copy Markdown

netlify Bot commented May 29, 2026

Deploy Preview for dashboard-v2-novu-staging canceled.

Name Link
🔨 Latest commit 09d06fb
🔍 Latest deploy log https://app.netlify.com/projects/dashboard-v2-novu-staging/deploys/6a19abfcc134140008e803b1

Comment on lines 93 to 119
@@ -128,11 +118,4 @@ export class WorkflowWorker extends WorkflowWorkerService {
});
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Missing-org path now silently drops jobs without a dedicated test

Previously, a missing organization caused an explicit early return with a clear log message. Now, if triggerEventUsecase.execute(data) throws because the organization doesn't exist, the job is swallowed by setSqsFailedHandler and permanently dropped (at-most-once). The spec has no test for this failure path — if the use-case doesn't handle a missing org gracefully and throws an unexpected error type, the failure will be invisible beyond the generic setSqsFailedHandler warning. Worth adding a test that stubs triggerEventUsecase.execute to throw and verifies the job is dropped (not retried).

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/worker/src/app/workflow/services/workflow.worker.ts
Line: 93-119

Comment:
**Missing-org path now silently drops jobs without a dedicated test**

Previously, a missing organization caused an explicit early return with a clear log message. Now, if `triggerEventUsecase.execute(data)` throws because the organization doesn't exist, the job is swallowed by `setSqsFailedHandler` and permanently dropped (at-most-once). The spec has no test for this failure path — if the use-case doesn't handle a missing org gracefully and throws an unexpected error type, the failure will be invisible beyond the generic `setSqsFailedHandler` warning. Worth adding a test that stubs `triggerEventUsecase.execute` to throw and verifies the job is dropped (not retried).

How can I resolve this? If you propose a fix, please make it concise.

Fix in Cursor

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 18a45ddf-b44f-423e-a25e-9ea5e61664e9

📥 Commits

Reviewing files that changed from the base of the PR and between 3951eed and 09d06fb.

📒 Files selected for processing (2)
  • apps/worker/src/app/workflow/services/workflow.worker.spec.ts
  • apps/worker/src/app/workflow/services/workflow.worker.ts
💤 Files with no reviewable changes (2)
  • apps/worker/src/app/workflow/services/workflow.worker.spec.ts
  • apps/worker/src/app/workflow/services/workflow.worker.ts

📝 Walkthrough

Walkthrough

WorkflowWorker removes its dependency on CommunityOrganizationRepository. The constructor parameter is deleted, the organization-existence validation in job processing is removed, and the organizationExist method is deleted. The test setup is updated to match the new constructor signature.

Changes

Remove WorkflowWorker organizationRepository dependency

Layer / File(s) Summary
Remove organizationRepository from WorkflowWorker
apps/worker/src/app/workflow/services/workflow.worker.ts
CommunityOrganizationRepository import is removed, constructor parameter is deleted, organization-existence check before job processing is removed, and the organizationExist method is deleted, so jobs proceed directly after the kill-switch check.
Update WorkflowWorker test constructor call
apps/worker/src/app/workflow/services/workflow.worker.spec.ts
Test setup is updated to construct WorkflowWorker without the organizationRepository argument.

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title follows Conventional Commits format with type 'refactor' and scope 'worker', uses lowercase imperative description, and ends with the Linear ticket reference 'fixes NV-7910'.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

@scopsy scopsy marked this pull request as ready for review May 29, 2026 15:14
@scopsy scopsy merged commit 322f9a8 into next May 29, 2026
39 checks passed
@scopsy scopsy deleted the cursor/remove-workflow-org-exist-query-458b branch May 29, 2026 15:19
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.

2 participants