Skip to content

Commit 3eb728e

Browse files
committed
update jobs for the simple function
1 parent 3bfa1e2 commit 3eb728e

4 files changed

Lines changed: 23 additions & 11 deletions

File tree

functions/simple-email/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"build:watch": "tsc -p tsconfig.json -w"
1515
},
1616
"dependencies": {
17-
"@launchql/knative-job-fn": "workspace:^"
17+
"@launchql/knative-job-fn": "workspace:^",
18+
"@launchql/postmaster": "0.1.4"
1819
}
1920
}

functions/simple-email/src/index.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import app from '@launchql/knative-job-fn';
2+
import { send as sendEmail } from '@launchql/postmaster';
23

34
type SimpleEmailPayload = {
45
to: string;
@@ -37,14 +38,29 @@ app.post('*', async (req: any, res: any, next: any) => {
3738
throw new Error("Either 'html' or 'text' must be provided");
3839
}
3940

40-
const from = isNonEmptyString(payload.from) ? payload.from : undefined;
41+
const fromEnv = process.env.MAILGUN_FROM;
42+
const from = isNonEmptyString(payload.from)
43+
? payload.from
44+
: isNonEmptyString(fromEnv)
45+
? fromEnv
46+
: undefined;
47+
4148
const replyTo = isNonEmptyString(payload.replyTo)
4249
? payload.replyTo
4350
: undefined;
4451

45-
// Log the email (dry-run mode, no actual send)
52+
// Send via @launchql/postmaster (Mailgun or configured provider)
53+
await sendEmail({
54+
to,
55+
subject,
56+
...(html && { html }),
57+
...(text && { text }),
58+
...(from && { from }),
59+
...(replyTo && { replyTo })
60+
});
61+
4662
// eslint-disable-next-line no-console
47-
console.log('[simple-email] DRY RUN email', {
63+
console.log('[simple-email] Sent email', {
4864
to,
4965
subject,
5066
from,
@@ -53,10 +69,6 @@ app.post('*', async (req: any, res: any, next: any) => {
5369
hasText: Boolean(text)
5470
});
5571

56-
// Optionally also log the full payload (for debugging)
57-
// eslint-disable-next-line no-console
58-
console.log('[simple-email] DRY RUN payload', payload);
59-
6072
res.status(200).json({ complete: true });
6173
} catch (err) {
6274
next(err);

jobs/knative-job-worker/src/env.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ const baseEnv = cleanEnv(
2121
{ dotEnvPath: null }
2222
);
2323

24-
const KNATIVE_SERVICE_URL =
25-
process.env.KNATIVE_SERVICE_URL || process.env.INTERNAL_GATEWAY_URL;
24+
const KNATIVE_SERVICE_URL = process.env.KNATIVE_SERVICE_URL;
2625

2726
if (!KNATIVE_SERVICE_URL) {
2827
throw new Error(

jobs/knative-job-worker/src/req.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const getFunctionUrl = (fn: string): string => {
1818
if (hasDevMap) {
1919
return DEV_MAP[fn] || completeUrl;
2020
}
21-
return `${env.KNATIVE_SERVICE_URL}/${fn}`;
21+
return `http://${fn}.${env.KNATIVE_SERVICE_URL}`;
2222
};
2323

2424
interface RequestOptions {

0 commit comments

Comments
 (0)