Skip to content

Commit

Permalink
feat: fix jobs and docker entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
dahal committed May 18, 2024
1 parent f4c61d4 commit f2b833d
Show file tree
Hide file tree
Showing 15 changed files with 291 additions and 290 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ NEXT_TELEMETRY_DISABLED=1

# Prisma
# https://www.prisma.io/docs/reference/database-reference/connection-urls#env
DATABASE_URL="postgres://captable:password@127.0.0.1:54321/captable"
DATABASE_URL="postgres://captable:password@pg:5432/captable"

# Next Auth
# You can generate a new secret on the command line with:
Expand Down
1 change: 1 addition & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
- POSTGRES_USER=captable
- POSTGRES_PASSWORD=password
- POSTGRES_DB=captable
- POSTGRES_EXTENSIONS=pgcrypto
ports:
- 54321:5432
volumes:
Expand Down
5 changes: 5 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,17 @@ COPY --from=builder --chown=nextjs:nodejs /app/scripts/migrate.sh ./scripts/migr
COPY --from=builder --chown=nextjs:nodejs /app/prisma/schema.prisma ./prisma/schema.prisma
COPY --from=builder --chown=nextjs:nodejs /app/prisma/migrations ./prisma/migrations


USER nextjs

EXPOSE 3000

ENV PORT 3000

# Run the migration script
RUN chmod +x ./scripts/migrate.sh
ENTRYPOINT [ "./scripts/migrate.sh" ]

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
CMD HOSTNAME="0.0.0.0" node server.js
539 changes: 268 additions & 271 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export async function register() {
if (process.env.NEXT_RUNTIME === "nodejs") {
const { initPgBoss } = await import("./lib/pg-boss-init");

await initPgBoss();
const { startJobs } = await import("@/jobs/start");
await startJobs();
}
}
2 changes: 1 addition & 1 deletion src/jobs/auth-verification-email.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AccountVerificationEmail from "@/emails/AccountVerificationEmail";
import { env } from "@/env";
import { BaseJob } from "@/lib/pg-boss-base";
import { BaseJob } from "@/jobs/base";
import { sendMail } from "@/server/mailer";
import { render } from "jsx-email";
import type { Job } from "pg-boss";
Expand Down
5 changes: 2 additions & 3 deletions src/lib/pg-boss-base.ts → src/jobs/base.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { JOB_TYPES } from "@/constants/job";
import type { JOB_TYPES } from "@/constants/job";
import { env } from "@/env";
import { singleton } from "@/lib/singleton";
import pgBoss from "pg-boss";

import { singleton } from "./singleton";

type JobTypes = typeof JOB_TYPES;

export type JobType = {
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/esign-confirmation-email.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ESignConfirmationEmail from "@/emails/EsignConfirmationEmail";
import { BaseJob } from "@/lib/pg-boss-base";
import { BaseJob } from "@/jobs/base";
import { sendMail } from "@/server/mailer";
import { render } from "jsx-email";
import type { Job } from "pg-boss";
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/esign-email.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import EsignEmail from "@/emails/EsignEmail";
import { env } from "@/env";
import { BaseJob } from "@/lib/pg-boss-base";
import { BaseJob } from "@/jobs/base";
import { db } from "@/server/db";
import { sendMail } from "@/server/mailer";
import { render } from "jsx-email";
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/esign-pdf.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseJob } from "@/lib/pg-boss-base";
import { BaseJob } from "@/jobs/base";
import { db } from "@/server/db";
import {
type EsignGetTemplateType,
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/member-inivite-email.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import MemberInviteEmail from "@/emails/MemberInviteEmail";
import { env } from "@/env";
import { BaseJob } from "@/jobs/base";
import { constants } from "@/lib/constants";
import { BaseJob } from "@/lib/pg-boss-base";
import { sendMail } from "@/server/mailer";
import { render } from "jsx-email";
import type { Job } from "pg-boss";
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/password-reset-email.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PasswordResetEmail from "@/emails/PasswordResetEmail";
import { env } from "@/env";
import { BaseJob } from "@/lib/pg-boss-base";
import { BaseJob } from "@/jobs/base";
import { sendMail } from "@/server/mailer";
import { render } from "jsx-email";
import type { Job } from "pg-boss";
Expand Down
4 changes: 2 additions & 2 deletions src/jobs/share-data-room-email.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ShareDataRoomEmail from "@/emails/ShareDataRoomEmail";
import { BaseJob } from "@/lib/pg-boss-base";
import { BaseJob } from "@/jobs/base";
import { sendMail } from "@/server/mailer";
import { render } from "jsx-email";
import { Job } from "pg-boss";
import type { Job } from "pg-boss";

export type DataRoomEmailPayloadType = {
link: string;
Expand Down
4 changes: 2 additions & 2 deletions src/jobs/share-update-email.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ShareUpdateEmail from "@/emails/ShareUpdateEmail";
import { BaseJob } from "@/lib/pg-boss-base";
import { BaseJob } from "@/jobs/base";
import { sendMail } from "@/server/mailer";
import { render } from "jsx-email";
import { Job } from "pg-boss";
import type { Job } from "pg-boss";

export type UpdateSharePayloadType = {
update: {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/pg-boss-init.ts → src/jobs/start.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { AuthVerificationEmailJob } from "@/jobs/auth-verification-email";
import { JobManager, boss } from "@/jobs/base";
import { EsignConfirmationEmailJob } from "@/jobs/esign-confirmation-email";
import { EsignNotificationEmailJob } from "@/jobs/esign-email";
import { EsignPdfJob } from "@/jobs/esign-pdf";
import { SendMemberInviteEmailJob } from "@/jobs/member-inivite-email";
import { PasswordResetEmailJob } from "@/jobs/password-reset-email";
import { ShareDataRoomEmailJob } from "@/jobs/share-data-room-email";
import { ShareUpdateEmailJob } from "@/jobs/share-update-email";
import { JobManager, boss } from "./pg-boss-base";

export async function initPgBoss() {
export async function startJobs() {
const jobs = new JobManager(boss)
.register(AuthVerificationEmailJob)
.register(ShareUpdateEmailJob)
Expand Down

0 comments on commit f2b833d

Please sign in to comment.