added support for sqs sample ripper when creating new products (#167)
This commit is contained in:
@@ -11,3 +11,4 @@ AWS_SECRET_ACCESS_KEY=
|
||||
AWS_ACCESS_KEY_ID=
|
||||
AWS_DEFAULT_REGION=eu-west-1
|
||||
BERNARD_QUEUE_URL=
|
||||
SAMPLE_SQS_QUEUE_URL=
|
||||
|
||||
@@ -13,6 +13,9 @@ GITHUB_REPO := Photowall/graphql-api-js
|
||||
AWS_REGION=$(shell aws configure get region)
|
||||
AWS_ACCOUNT_ID=$(shell aws sts get-caller-identity --query Account --output text)
|
||||
|
||||
$(eval SAMPLE_RIPPER_QUEUE_ARN_STAGING=$(shell aws ssm get-parameter --name /staging/SAMPLE_RIPPER_QUEUE_ARN --output text --query Parameter.Value))
|
||||
$(eval SAMPLE_RIPPER_QUEUE_ARN_PRODUCTION=$(shell aws ssm get-parameter --name /production/SAMPLE_RIPPER_QUEUE_ARN --output text --query Parameter.Value))
|
||||
|
||||
# HOSTED_ZONE=photowall.com default in the template
|
||||
# Cert ARN for the hosted zone
|
||||
CERTIFICATE_ARN='arn:aws:acm:eu-west-1:954747537408:certificate/1278df32-006d-48a4-abd6-2bfccabb11fd'
|
||||
@@ -27,6 +30,7 @@ ifeq ($(STACK_ENVIRONMENT_NAME),production)
|
||||
SUBDOMAIN=$(STACK_NAME)
|
||||
ENVIRONMENT_NAME=production
|
||||
BERNARD_QUEUE_ARN=arn:aws:sqs:eu-west-1:954747537408:photowall-bernard-production
|
||||
SAMPLE_RIPPER_QUEUE_ARN=$(SAMPLE_RIPPER_QUEUE_ARN_PRODUCTION)
|
||||
GITHUB_BRANCH=master
|
||||
DB_SECURITY_GROUP_ID=$(DB_SECURITY_GROUP_ID_PRODUCTION)
|
||||
CPU_SIZE=1024
|
||||
@@ -37,6 +41,7 @@ else ifeq ($(STACK_ENVIRONMENT_NAME),production-web)
|
||||
SUBDOMAIN=data
|
||||
ENVIRONMENT_NAME=production
|
||||
BERNARD_QUEUE_ARN=arn:aws:sqs:eu-west-1:954747537408:photowall-bernard-production
|
||||
SAMPLE_RIPPER_QUEUE_ARN=$(SAMPLE_RIPPER_QUEUE_ARN_PRODUCTION)
|
||||
GITHUB_BRANCH=master
|
||||
DB_SECURITY_GROUP_ID=$(DB_SECURITY_GROUP_ID_PRODUCTION)
|
||||
CPU_SIZE=1024
|
||||
@@ -47,6 +52,7 @@ else
|
||||
SUBDOMAIN=$(STACK_NAME)-$(STACK_ENVIRONMENT_NAME)
|
||||
ENVIRONMENT_NAME=$(STACK_ENVIRONMENT_NAME)
|
||||
BERNARD_QUEUE_ARN=arn:aws:sqs:eu-west-1:954747537408:photowall-bernard-stage
|
||||
SAMPLE_RIPPER_QUEUE_ARN=$(SAMPLE_RIPPER_QUEUE_ARN_STAGING)
|
||||
GITHUB_BRANCH=$(STACK_ENVIRONMENT_NAME)
|
||||
DB_SECURITY_GROUP_ID=$(DB_SECURITY_GROUP_ID_STAGING)
|
||||
CPU_SIZE=512
|
||||
@@ -106,6 +112,7 @@ create-stack: check-create-variables-set check-create-initial-ecr-image
|
||||
--tags Key=EnvironmentName,Value=$(STACK_ENVIRONMENT_NAME) \
|
||||
--parameters ParameterKey="EnvironmentName",ParameterValue="$(ENVIRONMENT_NAME)" \
|
||||
ParameterKey="BernardQueueArn",ParameterValue="${BERNARD_QUEUE_ARN}" \
|
||||
ParameterKey="SampleRipperQueueArn",ParameterValue="${SAMPLE_RIPPER_QUEUE_ARN}" \
|
||||
ParameterKey="Image",ParameterValue="$(DOCKER_IMAGE)" \
|
||||
ParameterKey="Subdomain",ParameterValue="$(SUBDOMAIN)" \
|
||||
ParameterKey="Certificate",ParameterValue="$(CERTIFICATE_ARN)" \
|
||||
@@ -125,6 +132,7 @@ update-stack: set-repository-lifecycle-policy
|
||||
--tags Key=EnvironmentName,Value=$(STACK_ENVIRONMENT_NAME) \
|
||||
--parameters ParameterKey="EnvironmentName",UsePreviousValue=true \
|
||||
ParameterKey="BernardQueueArn",ParameterValue="${BERNARD_QUEUE_ARN}" \
|
||||
ParameterKey="SampleRipperQueueArn",ParameterValue="${SAMPLE_RIPPER_QUEUE_ARN}" \
|
||||
ParameterKey="Image",UsePreviousValue=true \
|
||||
ParameterKey="Subdomain",UsePreviousValue=true \
|
||||
ParameterKey="Certificate",UsePreviousValue=true \
|
||||
|
||||
@@ -30,6 +30,10 @@ Parameters:
|
||||
Type: String
|
||||
Description: For policy connection the Bernard queue arn is required
|
||||
|
||||
SampleRipperQueueArn:
|
||||
Type: String
|
||||
Description: For policy connection the Sample Ripper queue arn is required
|
||||
|
||||
# CPU
|
||||
# 256 (.25 vCPU) - Available memory values: 0.5GB, 1GB, 2GB
|
||||
# 512 (.5 vCPU) - Available memory values: 1GB, 2GB, 3GB, 4GB
|
||||
@@ -155,6 +159,8 @@ Resources:
|
||||
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'
|
||||
- Name: 'SAMPLE_SQS_QUEUE_URL'
|
||||
ValueFrom: !Sub 'arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${EnvironmentName}/SAMPLE_RIPPER_QUEUE'
|
||||
- Name: 'NEW_RELIC_LICENSE_KEY'
|
||||
ValueFrom: !Sub 'arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/newrelic/LICENSE_KEY'
|
||||
# Send logs to CloudWatch Logs
|
||||
@@ -213,6 +219,10 @@ Resources:
|
||||
Action:
|
||||
- 'sqs:SendMessage'
|
||||
Resource: !Sub ${BernardQueueArn}
|
||||
- Effect: Allow
|
||||
Action:
|
||||
- 'sqs:SendMessage'
|
||||
Resource: !Sub ${SampleRipperQueueArn}
|
||||
|
||||
# A role for the containers
|
||||
TaskRole:
|
||||
|
||||
@@ -23,6 +23,7 @@ services:
|
||||
- AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION}
|
||||
- NODE_ENV=development
|
||||
- BERNARD_QUEUE_URL=${BERNARD_QUEUE_URL}
|
||||
- SAMPLE_SQS_QUEUE_URL=${SAMPLE_SQS_QUEUE_URL}
|
||||
- NEW_RELIC_LICENSE_KEY=${NEW_RELIC_LICENSE_KEY}
|
||||
- NEW_RELIC_APP_NAME=${NEW_RELIC_APP_NAME}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ services:
|
||||
- AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION}
|
||||
- NODE_ENV=development
|
||||
- BERNARD_QUEUE_URL=${BERNARD_QUEUE_URL}
|
||||
- SAMPLE_SQS_QUEUE_URL=${SAMPLE_SQS_QUEUE_URL}
|
||||
- NEW_RELIC_LICENSE_KEY=${NEW_RELIC_LICENSE_KEY}
|
||||
- NEW_RELIC_APP_NAME=${NEW_RELIC_APP_NAME}
|
||||
# - DEBUG=knex:*
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import {
|
||||
SQSClient,
|
||||
SendMessageCommand,
|
||||
SendMessageCommandOutput,
|
||||
SendMessageCommandInput,
|
||||
} from '@aws-sdk/client-sqs';
|
||||
|
||||
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);
|
||||
}
|
||||
+1
-21
@@ -1,9 +1,4 @@
|
||||
import {
|
||||
SQSClient,
|
||||
SendMessageCommand,
|
||||
SendMessageCommandOutput,
|
||||
SendMessageCommandInput,
|
||||
} from '@aws-sdk/client-sqs';
|
||||
import { sendMessage } from '../aws/sqs';
|
||||
|
||||
export async function sendPathChangedCmd(
|
||||
oldPath: string,
|
||||
@@ -20,18 +15,3 @@ export async function sendPathChangedCmd(
|
||||
};
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import { PrintProductDefaultsAPI } from '../datasources/printproduct-defaults-ap
|
||||
import { PrintProductDefaults } from '../types/printproduct-defaults-types';
|
||||
import { GraphQLError } from 'graphql';
|
||||
import { getOrientationString, isRepeatingPattern } from '../datasources/utils';
|
||||
import { sendMessage } from '../aws/sqs';
|
||||
|
||||
const ProductBlacklist = {
|
||||
async market(parent, _args, { dataSources }) {
|
||||
@@ -223,7 +224,16 @@ export const productMutationTypeDefs = {
|
||||
batch,
|
||||
designerId,
|
||||
);
|
||||
return (<ProductAPI>dataSources.productApi).getProduct(id);
|
||||
|
||||
const product = await (<ProductAPI>dataSources.productApi).getProduct(id);
|
||||
|
||||
// Send sqs message to trigger sample ripper
|
||||
await sendMessage(
|
||||
JSON.stringify({ productId: id, artNo: product.fields.artNo }),
|
||||
process.env.SAMPLE_SQS_QUEUE_URL,
|
||||
);
|
||||
|
||||
return product;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user