forked from pingcap/ossinsight
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
email-server, job-server: refactor email-server and job-server (pingc…
…ap#1054) refactor email-server and job-server
- Loading branch information
Showing
51 changed files
with
3,266 additions
and
995 deletions.
There are no files selected for viewing
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,27 @@ | ||
import axios, { AxiosInstance } from 'axios'; | ||
|
||
export interface SendEmailPayload { | ||
to: string; | ||
subject: string; | ||
templateName: EmailTemplateNames; | ||
templateData: Record<string, any>; | ||
} | ||
|
||
export enum EmailTemplateNames { | ||
REPO_FEEDS = 'repo-feeds', | ||
} | ||
|
||
export class EmailClient { | ||
private readonly httpClient: AxiosInstance; | ||
|
||
constructor (readonly baseURL: string) { | ||
this.httpClient = axios.create({ | ||
baseURL: baseURL, | ||
timeout: 3000, | ||
}); | ||
} | ||
|
||
async sendEmail (payload: SendEmailPayload): Promise<void> { | ||
return this.httpClient.post('/email', payload); | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 @@ | ||
export { SendEmailPayload, EmailTemplateNames, EmailClient } from './client'; |
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,48 @@ | ||
import { FastifyPluginAsync } from 'fastify'; | ||
import React from 'react'; | ||
import RepoMilestoneFeeds, { RepoMilestoneFeedsProps } from '../../emails/RepositoryFeeds'; | ||
import sendMail from '../../emails'; | ||
import { EmailTemplateNames, SendEmailPayload } from '../../client'; | ||
|
||
const schema = { | ||
body: { | ||
type: 'object', | ||
properties: { | ||
to: { type: 'string' }, | ||
subject: { type: 'string' }, | ||
templateName: { type: 'string' }, | ||
templateData: { type: 'object' }, | ||
}, | ||
}, | ||
}; | ||
|
||
const send: FastifyPluginAsync = async (app, opts): Promise<void> => { | ||
app.post<{ | ||
Body: SendEmailPayload; | ||
}>('/', { | ||
schema, | ||
}, async function (req, reply) { | ||
const { | ||
to, subject, templateName, templateData, | ||
} = req.body; | ||
|
||
let component = null; | ||
switch (templateName) { | ||
case EmailTemplateNames.REPO_FEEDS: | ||
component = React.createElement(RepoMilestoneFeeds, templateData as RepoMilestoneFeedsProps); | ||
break; | ||
default: | ||
throw new Error(`Unknown template name: ${String(templateName)}`); | ||
} | ||
|
||
await sendMail({ | ||
subject, | ||
to, | ||
component, | ||
}); | ||
|
||
void reply.send({ success: true }); | ||
}); | ||
}; | ||
|
||
export default send; |
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 { FastifyBaseLogger, FastifyInstance, FastifyTypeProviderDefault, RawServerDefault } from 'fastify'; | ||
import { IncomingMessage, ServerResponse } from 'http'; | ||
|
||
import { Params } from 'fastify-cron'; | ||
|
||
export type FastifyServer = FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault>; | ||
|
||
export type JobName = string; | ||
|
||
export type CronJobDef = Params; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Oops, something went wrong.