Skip to content

feat(mono): Add worker app#121

Merged
Nudelsuppe42 merged 31 commits into
mainfrom
worker
Jun 1, 2026
Merged

feat(mono): Add worker app#121
Nudelsuppe42 merged 31 commits into
mainfrom
worker

Conversation

@Nudelsuppe42
Copy link
Copy Markdown
Contributor

@Nudelsuppe42 Nudelsuppe42 commented May 22, 2026

This pull request introduces a new standalone worker service in the apps/worker directory, including its configuration, infrastructure, and several utility libraries. The worker is responsible for handling events, background jobs, and scheduled (cron) tasks. See #120 for implementation ideas.

Added Jobs

Common

  • SEND_DISCORD_DM: Send a DM to (a) user(s):
    const discordDmPayloadSchema = z
    .object({
    userId: z.string().min(1).optional(),
    userIds: z.array(z.string().min(1)).optional(),
    discordId: z.string().min(1).optional(),
    discordIds: z.array(z.string().min(1)).optional(),
    content: discordBotMessageMessageSchema.or(z.string()),
    })
    .refine((data) => Boolean(data.userId || data.userIds || data.discordId || data.discordIds), {
    message: 'Invalid payload: at least one discordId or userId must be provided',
    });
  • SEND_DISCORD_LOG: Send a log message to staff:
    const discordLogPayloadSchema = z.any();
  • BUILDTEAM_WEBHOOK: Send a webhook to a BuildTeam:
    const auditLogBtPayloadSchema = z.object({
    type: z.enum(AuditLogBuildTeamType),
    data: z.unknown().optional(),
    destination: z.array(webhookBuildTeamSchema),
    });

Administrative / Cron

  • REVIEW_ACTIVITY_CHECK: Calculate latest review activities (daily)
  • PURGE_CLAIMS: Purge claims with no area or no ID (daily)
  • PURGE_VERIFICATIONS: Purge old verification codes (daily)
  • REMIND_APPLICATIONS: Send an reminder to all BuildTeams with applications older than 14 days (weekly)

@Nudelsuppe42 Nudelsuppe42 marked this pull request as ready for review May 27, 2026 15:16
@Nudelsuppe42 Nudelsuppe42 requested review from Copilot and kyanvde May 27, 2026 15:16
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new apps/worker service to run BullMQ-backed background jobs and scheduled cron tasks, alongside worker deployment/build plumbing and some DB type exports needed by the worker.

Changes:

  • Added a new apps/worker app with BullMQ worker execution, cron registration, and task implementations (Discord DMs/logging, BuildTeam webhooks, administrative cleanup/reminders, review activity reporting).
  • Added worker build/deploy infrastructure (Dockerfile + GitHub Actions workflow) and workspace dependency updates.
  • Added/updated DB type exports and generated Prisma type declarations to support worker usage.

Reviewed changes

Copilot reviewed 31 out of 37 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
yarn.lock Adds BullMQ/ioredis/tsx/winston/zod and the new worker workspace dependency graph.
README.md Lists the new apps/worker application in the monorepo overview.
packages/db/src/index.d.ts Exposes generated Prisma client types via package entrypoint typings.
packages/db/src/generated/prisma/models.d.ts Adds generated model type re-exports.
packages/db/src/generated/prisma/enums.d.ts Adds generated enum type declarations.
packages/db/src/generated/prisma/commonInputTypes.d.ts Adds generated Prisma input/filter typings.
packages/db/src/generated/prisma/client.d.ts Adds generated Prisma client typings and model type exports.
apps/worker/tsconfig.json Worker TypeScript compiler configuration (NodeNext, build output to dist).
apps/worker/tsconfig.runtime.json Runtime tsconfig override (adds @repo/* paths).
apps/worker/tsconfig.test.json Test tsconfig override for running the test script.
apps/worker/test/index.test.ts Adds a script-style “test” that enqueues a job into Redis/BullMQ.
apps/worker/src/util/reviewActivity.ts Implements review-activity score calculation for BuildTeams.
apps/worker/src/tasks/index.ts Registers all tasks into the worker task registry.
apps/worker/src/tasks/base.task.ts Defines a BaseTask abstraction with Zod validation + Prisma/logger context.
apps/worker/src/tasks/discord/sendLog.task.ts Implements a task to send logs to a Discord webhook.
apps/worker/src/tasks/discord/sendDm.task.ts Implements a task to send Discord DMs (with retry-on-partial-failure behavior).
apps/worker/src/tasks/buildteams/sendWebhook.task.ts Implements a task to send BuildTeam webhooks with retry-on-partial-failure.
apps/worker/src/tasks/administrative/reviewActivityCheck.task.ts Implements the daily review-activity check logic + Discord reporting.
apps/worker/src/tasks/administrative/purgeClaims.task.ts Implements daily purge logic for invalid/unreferenced claims.
apps/worker/src/tasks/administrative/purgeVerifications.task.ts Implements daily purge logic for old Minecraft verification codes.
apps/worker/src/tasks/administrative/remindApplications.task.ts Implements weekly reminders for BuildTeams with old pending applications.
apps/worker/src/queue/base.worker.ts Implements BullMQ Worker processing and failure reporting.
apps/worker/src/queue/cron.manager.ts Implements cron registration/scheduling via BullMQ repeatable jobs.
apps/worker/src/main.ts Bootstraps Prisma, starts the worker, and registers cron jobs.
apps/worker/src/lib/config.ts Worker config constants (queue name, retries, retention, webhook URLs).
apps/worker/src/lib/logger.ts Winston logger configuration/formatting for dev/prod.
apps/worker/src/lib/prisma.ts Prisma client initialization using @prisma/adapter-pg + an upload src computed field.
apps/worker/src/lib/redis.ts ioredis client initialization + connection lifecycle logging.
apps/worker/src/lib/discordWebhook.ts Simple Discord webhook sender wrapper with error handling.
apps/worker/src/lib/discordBot.ts Bot API integration for sending DMs + Zod schema for structured messages.
apps/worker/src/lib/buildteamWebhook.ts BuildTeam webhook sender + BuildTeam webhook URL resolver.
apps/worker/package.json Defines worker scripts/deps (BullMQ, ioredis, zod, winston, tsx).
apps/worker/README.md Adds a basic README for the worker app.
apps/worker/Dockerfile Adds a multi-stage Docker build for the worker.
apps/worker/.infisical.json Adds Infisical configuration for worker secrets.
.vscode/settings.json Adds worker paths to VS Code settings.
.github/workflows/worker.yml Adds a GitHub Actions workflow to build/publish the worker Docker image and tag releases.

Comment thread apps/worker/src/queue/base.worker.ts Outdated
Comment thread apps/worker/src/main.ts
Comment thread apps/worker/src/util/reviewActivity.ts
Comment thread apps/worker/src/tasks/buildteams/sendWebhook.task.ts Outdated
Comment thread apps/worker/src/lib/discordBot.ts Outdated
Comment thread apps/worker/src/tasks/administrative/remindApplications.task.ts Outdated
Comment thread apps/worker/src/tasks/administrative/purgeClaims.task.ts Outdated
Comment thread apps/worker/README.md Outdated
Comment thread apps/worker/Dockerfile Outdated
Comment thread apps/worker/src/queue/cron.manager.ts Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 31 out of 37 changed files in this pull request and generated 7 comments.

Comment thread apps/worker/src/util/reviewActivity.ts
Comment thread apps/worker/src/util/reviewActivity.ts
Comment thread apps/worker/src/tasks/administrative/remindApplications.task.ts Outdated
Comment thread apps/worker/src/tasks/administrative/remindApplications.task.ts Outdated
Comment thread apps/worker/src/tasks/administrative/reviewActivityCheck.task.ts
Comment thread apps/worker/src/lib/buildteamWebhook.ts
Comment thread apps/worker/src/tasks/discord/sendDm.task.ts Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 31 out of 37 changed files in this pull request and generated 13 comments.

Comment thread apps/worker/src/queue/base.worker.ts Outdated
Comment thread apps/worker/src/queue/cron.manager.ts Outdated
Comment thread apps/worker/src/tasks/discord/sendDm.task.ts Outdated
Comment thread apps/worker/src/tasks/discord/sendLog.task.ts Outdated
Comment thread apps/worker/src/tasks/buildteams/sendWebhook.task.ts Outdated
Comment thread apps/worker/src/queue/base.worker.ts
Comment thread apps/worker/src/tasks/administrative/reviewActivityCheck.task.ts
Comment thread apps/worker/src/tasks/administrative/remindApplications.task.ts
Comment thread apps/worker/src/util/reviewActivity.ts
Comment thread apps/worker/src/lib/discordBot.ts
Nudelsuppe42 and others added 3 commits May 27, 2026 18:08
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 31 out of 37 changed files in this pull request and generated 10 comments.

Comment thread apps/worker/Dockerfile
Comment thread apps/worker/src/lib/discordWebhook.ts
Comment thread apps/worker/src/queue/cron.manager.ts
Comment thread apps/worker/src/tasks/administrative/reviewActivityCheck.task.ts
Comment thread apps/worker/src/lib/redis.ts
Comment thread apps/worker/src/lib/discordBot.ts
Comment thread apps/worker/src/tasks/administrative/remindApplications.task.ts
Comment thread apps/worker/src/util/reviewActivity.ts
Comment thread apps/worker/test/index.test.ts
Comment thread apps/worker/src/tasks/discord/sendDm.task.ts Outdated
Copy link
Copy Markdown
Contributor

@kyanvde kyanvde left a comment

Choose a reason for hiding this comment

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

As long as you tested if everything works this looks good to me. I left a few comments about some nitpicky things. Something that might be a good idea to still add is a small docblock above every task explaining what they do (like what you did in the PR description).

Comment thread apps/worker/src/lib/buildteamWebhook.ts
Comment thread apps/worker/src/lib/discordWebhook.ts
Comment thread apps/worker/src/queue/base.worker.ts
@Nudelsuppe42 Nudelsuppe42 self-assigned this Jun 1, 2026
@Nudelsuppe42 Nudelsuppe42 merged commit a4a5d30 into main Jun 1, 2026
4 checks passed
@Nudelsuppe42 Nudelsuppe42 deleted the worker branch June 1, 2026 13:35
@github-project-automation github-project-automation Bot moved this from In Progress to Done in @BuildTheEarth/web Tracker Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

feat(mono): ⭐ Event Queue and Worker

3 participants