-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Rajat Saxena <[email protected]>
- Loading branch information
1 parent
85c57dc
commit 57af357
Showing
70 changed files
with
751 additions
and
32 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file added
BIN
+9.63 KB
.yarn/cache/@msgpackr-extract-msgpackr-extract-darwin-arm64-npm-3.0.2-18ac236cc4-8.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+9.33 KB
.yarn/cache/node-abort-controller-npm-3.1.1-e246ed42cd-2c340916af.zip
Binary file not shown.
Binary file added
BIN
+7.04 KB
.yarn/cache/node-gyp-build-optional-packages-npm-5.0.7-40f21a5d68-bcb4537af1.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { MailJob } from "./model/mail-job"; | ||
import mailQueue from "./queue"; | ||
|
||
export async function addMailJob({ to, subject, body, from }: MailJob) { | ||
for (let recipient of to) { | ||
await mailQueue.add("mail", { | ||
to: recipient, | ||
subject, | ||
body, | ||
from, | ||
}); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { z } from "zod"; | ||
|
||
export const MailJob = z.object({ | ||
to: z.string().array(), | ||
from: z.string(), | ||
subject: z.string(), | ||
body: z.string(), | ||
}); | ||
|
||
export type MailJob = z.infer<typeof MailJob>; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Queue } from "bullmq"; | ||
import redis from "../../redis"; | ||
|
||
const mailQueue = new Queue("mail", { connection: redis }); | ||
|
||
export default mailQueue; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Worker } from "bullmq"; | ||
import nodemailer from "nodemailer"; | ||
import redis from "../../redis"; | ||
import { logger } from "../../logger"; | ||
|
||
const transporter = nodemailer.createTransport({ | ||
host: process.env.EMAIL_HOST, | ||
port: +(process.env.EMAIL_PORT || 587), | ||
auth: { | ||
user: process.env.EMAIL_USER, | ||
pass: process.env.EMAIL_PASS, | ||
}, | ||
}); | ||
|
||
const worker = new Worker( | ||
"mail", | ||
async (job) => { | ||
const { to, from, subject, body } = job.data; | ||
|
||
try { | ||
await transporter.sendMail({ | ||
from, | ||
to, | ||
subject, | ||
html: body, | ||
}); | ||
} catch (err: any) { | ||
logger.error(err); | ||
} | ||
}, | ||
{ connection: redis }, | ||
); | ||
|
||
export default worker; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
import { connectToDatabase } from "./db"; | ||
import { processOngoingSequences } from "./domain/mail/process-ongoing-sequences"; | ||
import { processRules } from "./domain/mail/process-rules"; | ||
import express from "express"; | ||
import jobRoutes from "./job/routes"; | ||
|
||
(async () => { | ||
await connectToDatabase(); | ||
// start workers | ||
import "./domain/mail/worker"; | ||
import { startEmailAutomation } from "./start-email-automation"; | ||
|
||
processOngoingSequences(); | ||
processRules(); | ||
})(); | ||
const app = express(); | ||
app.use(express.json()); | ||
|
||
app.use("/job", jobRoutes); | ||
|
||
startEmailAutomation(); | ||
|
||
const port = process.env.PORT || 80; | ||
app.listen(port, () => { | ||
console.log(`Queue server running at ${port}`); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import express from "express"; | ||
import { addMailJob } from "../domain/mail/handler"; | ||
import { logger } from "../logger"; | ||
import { MailJob } from "../domain/mail/model/mail-job"; | ||
|
||
const router = express.Router(); | ||
|
||
router.post("/mail", async (req: express.Request, res: express.Response) => { | ||
try { | ||
const { to, from, subject, body } = req.body; | ||
MailJob.parse({ to, from, subject, body }); | ||
|
||
await addMailJob({ to, from, subject, body }); | ||
|
||
res.status(200).json({ message: "Success" }); | ||
} catch (err: any) { | ||
logger.error(err); | ||
res.status(500).json({ error: err.message }); | ||
} | ||
}); | ||
|
||
export default router; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default { | ||
host: process.env.REDIS_HOST || "localhost", | ||
port: +(process.env.REDIS_PORT || 6379), | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { connectToDatabase } from "./db"; | ||
import { processOngoingSequences } from "./domain/mail/process-ongoing-sequences"; | ||
import { processRules } from "./domain/mail/process-rules"; | ||
|
||
export async function startEmailAutomation() { | ||
await connectToDatabase(); | ||
|
||
processOngoingSequences(); | ||
processRules(); | ||
} |
Oops, something went wrong.
57af357
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
courselit – ./
courselit-codelit.vercel.app
courselit-git-main-codelit.vercel.app
*.clqa.xyz