Add bernard sqs msg to add redirect for changed paths (#73)
This commit is contained in:
+1
-1
@@ -5,4 +5,4 @@ INTERIORS_URL=https://0hrq0zel2h.execute-api.eu-west-1.amazonaws.com/Prod
|
|||||||
AWS_SECRET_ACCESS_KEY=
|
AWS_SECRET_ACCESS_KEY=
|
||||||
AWS_ACCESS_KEY_ID=
|
AWS_ACCESS_KEY_ID=
|
||||||
AWS_DEFAULT_REGION=eu-west-1
|
AWS_DEFAULT_REGION=eu-west-1
|
||||||
|
BERNARD_QUEUE_URL=
|
||||||
|
|||||||
@@ -136,6 +136,8 @@ Resources:
|
|||||||
ValueFrom: !Sub 'arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${EnvironmentName}/INTERIORS_URL'
|
ValueFrom: !Sub 'arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${EnvironmentName}/INTERIORS_URL'
|
||||||
- Name: 'INTERIORS_TOKEN'
|
- Name: 'INTERIORS_TOKEN'
|
||||||
ValueFrom: !Sub 'arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${EnvironmentName}/INTERIORS_TOKEN'
|
ValueFrom: !Sub 'arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${EnvironmentName}/INTERIORS_TOKEN'
|
||||||
|
- Name: 'BERNARD_QUEUE_URL'
|
||||||
|
ValueFrom: !Sub 'arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${EnvironmentName}/sqs/PHOTOWALL_BERNARD_TASKS_QUEUE_URL'
|
||||||
# Send logs to CloudWatch Logs
|
# Send logs to CloudWatch Logs
|
||||||
LogConfiguration:
|
LogConfiguration:
|
||||||
LogDriver: awslogs
|
LogDriver: awslogs
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ services:
|
|||||||
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
|
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
|
||||||
- AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION}
|
- AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION}
|
||||||
- NODE_ENV=development
|
- NODE_ENV=development
|
||||||
|
- BERNARD_QUEUE_URL=${BERNARD_QUEUE_URL}
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
default:
|
default:
|
||||||
|
|||||||
Generated
+1354
File diff suppressed because it is too large
Load Diff
@@ -14,6 +14,7 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-s3": "^3.31.0",
|
"@aws-sdk/client-s3": "^3.31.0",
|
||||||
|
"@aws-sdk/client-sqs": "^3.36.1",
|
||||||
"@aws-sdk/s3-request-presigner": "^3.31.0",
|
"@aws-sdk/s3-request-presigner": "^3.31.0",
|
||||||
"apollo-datasource": "^3.1.0",
|
"apollo-datasource": "^3.1.0",
|
||||||
"apollo-datasource-rest": "^3.2.0",
|
"apollo-datasource-rest": "^3.2.0",
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
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> {
|
||||||
|
console.log('Senfing', body);
|
||||||
|
const client = new SQSClient({ region: 'eu-west-1' });
|
||||||
|
|
||||||
|
const params: SendMessageCommandInput = {
|
||||||
|
MessageBody: body,
|
||||||
|
QueueUrl: queueUrl,
|
||||||
|
};
|
||||||
|
const sendMessageCommand = new SendMessageCommand(params);
|
||||||
|
|
||||||
|
return client.send(sendMessageCommand);
|
||||||
|
}
|
||||||
@@ -27,6 +27,7 @@ import {
|
|||||||
roundOrDefaultTo,
|
roundOrDefaultTo,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
import { UserInputError } from 'apollo-server';
|
import { UserInputError } from 'apollo-server';
|
||||||
|
import { sendPathChangedCmd } from '../bernard/client';
|
||||||
|
|
||||||
const MINUTE = 60;
|
const MINUTE = 60;
|
||||||
|
|
||||||
@@ -362,6 +363,10 @@ export class ProductAPI extends BaseSQLDataSource {
|
|||||||
): Promise<any[]> {
|
): Promise<any[]> {
|
||||||
// Check path and insert new unique path if taken
|
// Check path and insert new unique path if taken
|
||||||
const uniquePath = await this.getUniqueProductPath(info.path, productId);
|
const uniquePath = await this.getUniqueProductPath(info.path, productId);
|
||||||
|
const oldProd = await this.getProduct(productId);
|
||||||
|
if (oldProd.path !== uniquePath) {
|
||||||
|
sendPathChangedCmd(oldProd.path, uniquePath);
|
||||||
|
}
|
||||||
|
|
||||||
const promises = [];
|
const promises = [];
|
||||||
promises.push(
|
promises.push(
|
||||||
@@ -397,6 +402,7 @@ export class ProductAPI extends BaseSQLDataSource {
|
|||||||
info.printFileDpi.toString(),
|
info.printFileDpi.toString(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return Promise.all(promises);
|
return Promise.all(promises);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user