Skip to content

Commit

Permalink
Updating file-expiry scripts, and renaming WatcloudEmail -> Email
Browse files Browse the repository at this point in the history
  • Loading branch information
cehune committed Oct 23, 2024
1 parent 152f427 commit 8740170
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 77 deletions.
2 changes: 1 addition & 1 deletion emails/_common/watcloud-email.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getAsset, registerAsset, WATcloudURI } from "../../utils/watcloud-uri";
registerAsset('watcloud-logo', new WATcloudURI("watcloud://v1/sha256:393767e36d5387815c15d11c506c3c820de5db41723ffc062751673621dedb15?name=1024x512%20black%401x.png"))

// Wrapper for WATcloud-themed emails
export function WATcloudEmail({
export function Email({
previewText,
children,
}: {
Expand Down
6 changes: 3 additions & 3 deletions emails/blog-update.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "@react-email/components";
import { z } from "zod";
import { getAsset, registerAsset, WATcloudURI } from "../utils/watcloud-uri";
import { WATcloudEmail } from "./_common/watcloud-email";
import { Email } from "./_common/watcloud-email";

const WATcloudBlogUpdateEmailProps = z.object({
url: z.string().url(),
Expand Down Expand Up @@ -37,7 +37,7 @@ export function WATcloudBlogUpdateEmail(props: WATcloudBlogUpdateEmailProps) {
const imageSrc = getAsset(image).resolveFromCache();

return (
<WATcloudEmail previewText={previewText}>
<Email previewText={previewText}>
<Text>Hello! WATcloud has published a new blog post.</Text>
<Hr style={{ marginTop: "20px", marginBottom: "20px" }} />
<Img src={imageSrc} alt={title} height="200" />
Expand All @@ -51,7 +51,7 @@ export function WATcloudBlogUpdateEmail(props: WATcloudBlogUpdateEmailProps) {
<Link href={url}>Read more →</Link>
<Hr style={{ marginTop: "20px", marginBottom: "20px" }} />
<Text style={{ color: "#666", fontSize: "12px" }}>You are receiving this email because you are subscribed to the WATcloud blog.</Text>
</WATcloudEmail>
</Email>
);
};

Expand Down
94 changes: 94 additions & 0 deletions emails/file-expiry.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import {
Hr,
Link,
Section,
Text
} from "@react-email/components";
import { z } from "zod";
import { Email } from "./_common/watcloud-email";

const EmailProps = z.object({
name: z.string(),
paths: z.array(z.string()),
daysForExpiry: z.string(),
deletionDate: z.string()
});

type EmailProps = z.infer<typeof EmailProps>;

export const FileExpiryEmail = (props: EmailProps) => {
const { name, paths, daysForExpiry, deletionDate} = EmailProps.parse(props);

const previewText = `You have expired files in the WATO drives`;
const mapPathToMachine = (): Record<string, string[]> => {
const pathMap: Record<string, string[]> = {};

paths.forEach((path: string) => {
const index = path.indexOf(":");
let machine = "";
let filepath = "";

if (index < 0) {
machine = "Shared storage across machines - Access on any machine";
filepath = path;
} else {
[machine, filepath] = path.split(":", 2);
}

// Initialize array for machine if it doesn't exist, then push the filepath
if (!pathMap[machine]) {
pathMap[machine] = [];
}
pathMap[machine].push(filepath);
});

return pathMap; // Return the pathMap object
};

const pathMap = mapPathToMachine();

const expiredPaths = (
<div>
{Object.keys(pathMap).map((machine) => (
<div key={machine}>
<ul key={machine} style={{ fontSize: "14px", lineHeight: "24px" }}>
<li>{machine}</li>
<ul>
{pathMap[machine]?.map((path, pathIndex) => (
<li key={pathIndex}>{path}</li>
))}
</ul>
</ul>
</div>
))}
</div>
);

return (
<Email previewText={previewText}>
<Text>Hi {name},</Text>
<Text>
In an ongoing effort to keep WATcloud's file storage efficient and maintain optimal performance, we routinely clean up specific directories that haven't been accessed in the past {daysForExpiry} days. </Text>
<Hr />
<Section>
<Text>The following paths on each respective machine are expired:</Text>
{expiredPaths}
</Section>
<Hr />
<Text style={{ fontWeight: 'bold' }}>
If you do not access files in any of these directories, then they will be automatically deleted on {deletionDate}. </Text>
<Text>
If you have any questions, please reach out to your <Link href="https://cloud.watonomous.ca/docs/services#watcloud-contact" style={{ color: "#1e90ff", textDecoration: "none" }}>WATcloud contact</Link> or the WATcloud team at <Link href={`mailto:[email protected]`} style={{ color: "#1e90ff", textDecoration: "none" }}>[email protected]</Link>.
</Text>
</Email>
);
};

FileExpiryEmail.PreviewProps = {
name: "John Doe",
paths: ["delta-ubuntu2:/var/lib/cluster/users/1234/docker", "tr-ubuntu3:/var/lib/cluster/users/1234/containers", "delta-ubuntu2:/var/lib/cluster/users/1234/containers", "/mnt/wato-drive2/someuser", "/mnt/wato-drive2/other"],
daysForExpiry: "70",
deletionDate: "2025-01-01"
} as EmailProps;

export default FileExpiryEmail;
70 changes: 0 additions & 70 deletions emails/file_expiry.tsx

This file was deleted.

6 changes: 3 additions & 3 deletions emails/onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "@react-email/components";
import dedent from "dedent-js";
import { z } from "zod";
import { WATcloudEmail } from "./_common/watcloud-email";
import { Email } from "./_common/watcloud-email";

const WATcloudOnboardingEmailProps = z.object({
name: z.string(),
Expand All @@ -28,7 +28,7 @@ export const WATcloudOnboardingEmail = (props: WATcloudOnboardingEmailProps) =>
)

return (
<WATcloudEmail previewText={previewText}>
<Email previewText={previewText}>
<Text>Hi {name},</Text>
<Text>
Welcome to WATcloud, WATonomous's compute cluster and infrastructure. We are excited to have you on board!
Expand Down Expand Up @@ -61,7 +61,7 @@ export const WATcloudOnboardingEmail = (props: WATcloudOnboardingEmailProps) =>
`)}
</pre>
<Text>WATcloud Onboarding Bot 🤖</Text>
</WATcloudEmail>
</Email>
);
};

Expand Down

0 comments on commit 8740170

Please sign in to comment.