38 lines
902 B
TypeScript
38 lines
902 B
TypeScript
import {
|
|
SQSClient,
|
|
SendMessageCommand,
|
|
SendMessageCommandOutput,
|
|
SendMessageCommandInput,
|
|
} from '@aws-sdk/client-sqs';
|
|
|
|
export async function sendPathChangedCmd(
|
|
oldPath: string,
|
|
newPath: string,
|
|
): Promise<void> {
|
|
const msg = {
|
|
args: {
|
|
name: 'AddRedirect',
|
|
old: oldPath,
|
|
new: newPath,
|
|
},
|
|
class: 'Bernard:Message:DefaultMessage',
|
|
timestamp: Math.round(Date.now() / 1000), // Epoch seconds
|
|
};
|
|
await sendMessage(JSON.stringify(msg), process.env.BERNARD_QUEUE_URL);
|
|
}
|
|
|
|
export async function sendMessage(
|
|
body: string,
|
|
queueUrl: string,
|
|
): Promise<SendMessageCommandOutput | undefined> {
|
|
const client = new SQSClient({ region: 'eu-west-1' });
|
|
|
|
const params: SendMessageCommandInput = {
|
|
MessageBody: body,
|
|
QueueUrl: queueUrl,
|
|
};
|
|
const sendMessageCommand = new SendMessageCommand(params);
|
|
|
|
return client.send(sendMessageCommand);
|
|
}
|