Add email campaign pipeline, recipient resolution, delete endpoint, email send scheduler - #365
Open
williamchiii wants to merge 5 commits into
Open
Add email campaign pipeline, recipient resolution, delete endpoint, email send scheduler#365williamchiii wants to merge 5 commits into
williamchiii wants to merge 5 commits into
Conversation
Resolves applicant recipient groups to deduped contact emails (excluding
is_fake seeded rows), adds raw-HTML task type and SES send methods, registers
all task types in the email worker mux, and adds SendCampaign with
draft/scheduled -> sending -> sent/failed transitions plus an admin-gated
POST /email/campaigns/{campaignId}/send endpoint.
Adds GetUserContactEmailsByRoles (role-based lookup on users, excluding is_fake rows) and a recipientRoles map, so resolveRecipients now dispatches applicant groups by application status and role groups by user role. Only interest_subscribers remains unsupported.
Introduces campaignStore and campaignMailer interfaces in the email package so the campaign service can be tested with fakes (concrete repository and email service satisfy them unchanged). Adds 8 tests covering per-recipient queueing, format routing, cross-group dedup, status transitions including sending->failed with last_error, and the guard paths. test: cover SendCampaign send pipeline Introduces campaignStore and campaignMailer interfaces in the email package so the campaign service can be tested with fakes (concrete repository and email service satisfy them unchanged). Adds 8 tests covering per-recipient queueing, format routing, cross-group dedup, status transitions including sending->failed with last_error, and the guard paths.
Adds DeleteEmailCampaign query, repo method, and a DeleteCampaign service
method guarded by canDeleteCampaign so draft, scheduled, and failed campaigns
can be removed while sent and sending ones stay on the record. Exposes
DELETE /email/campaigns/{campaignId} with OpenAPI docs.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Adds an asynq Scheduler in cmd/email_worker that sweeps every minute for campaigns whose scheduled_at has passed, failing any more than two hours late so an outage cannot trigger a surprise blast. Sends are now claimed with a conditional UPDATE, so overlapping ticks or a double-clicked Send cannot dispatch the same campaign twice. Also resolves interest_subscribers, completing all seven recipient types.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces significant improvements to the email campaign system, focusing on enabling scheduled campaign sending, expanding recipient resolution, and enhancing repository and SQL support for these features. The changes span new SQL queries, repository methods, background worker scheduling, and service wiring.
Summary of Most Important Changes:
Scheduled Email Campaigns
apps/api/cmd/email_worker/main.goEmail Campaign Recipient Resolution
These methods ensure campaigns reach the correct audience segments. (
apps/api/internal/database/queries/email_campaigns.sqlEmail Campaign State Management
Added atomic "claim for sending" logic to ensure that only one worker can transition a campaign to "sending" at a time, preventing duplicate sends in concurrent environments. (
apps/api/internal/database/queries/email_campaigns.sqlAdded deletion support for email campaigns, scoped by hackathon to prevent cross-event data issues. (
apps/api/internal/database/queries/email_campaigns.sqlApplication and User Model Enhancements
is_fakeflag, allowing filtering of test or fake users/applications from recipient lists. (apps/api/internal/database/sqlc/applications.sql.goService Wiring and Handler Updates
EmailCampaignServicewith its dependencies, ensuring campaign logic is available in both the API and worker processes. (apps/api/cmd/email_worker/main.goThese changes collectively enable robust, scheduled, and targeted email campaigns, while laying groundwork for further automation and reliability in campaign delivery.