Send ProductUpdated SQS event for cache invalidation (#175)
This commit is contained in:
@@ -15,3 +15,19 @@ export async function sendPathChangedCmd(
|
||||
};
|
||||
await sendMessage(JSON.stringify(msg), process.env.BERNARD_QUEUE_URL);
|
||||
}
|
||||
|
||||
export async function sendProductUpdatedEvent(
|
||||
productIds: (string | number)[],
|
||||
caches: string[],
|
||||
): Promise<void> {
|
||||
const msg = {
|
||||
args: {
|
||||
name: 'ProductUpdated',
|
||||
ids: productIds,
|
||||
caches: caches,
|
||||
},
|
||||
class: 'Bernard:Message:DefaultMessage',
|
||||
timestamp: Math.round(Date.now() / 1000), // Epoch seconds
|
||||
};
|
||||
await sendMessage(JSON.stringify(msg), process.env.BERNARD_QUEUE_URL);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import { PrintProductDefaults } from '../types/printproduct-defaults-types';
|
||||
import { GraphQLError } from 'graphql';
|
||||
import { getOrientationString, isRepeatingPattern } from '../datasources/utils';
|
||||
import { sendMessage } from '../aws/sqs';
|
||||
import { sendProductUpdatedEvent } from '../bernard/client';
|
||||
|
||||
const ProductBlacklist = {
|
||||
async market(parent, _args, { dataSources }) {
|
||||
@@ -271,6 +272,7 @@ export const productMutationTypeDefs = {
|
||||
productId,
|
||||
info,
|
||||
);
|
||||
await sendProductUpdatedEvent([productId], ['product']);
|
||||
return (<ProductAPI>dataSources.productApi).getProduct(productId);
|
||||
},
|
||||
|
||||
@@ -320,6 +322,10 @@ export const productMutationTypeDefs = {
|
||||
productId,
|
||||
groupIds,
|
||||
);
|
||||
|
||||
// Clear the cache to remove the old data
|
||||
await sendProductUpdatedEvent([productId], ['product_groups']);
|
||||
|
||||
const product = await (<ProductAPI>dataSources.productApi).getProduct(
|
||||
productId,
|
||||
);
|
||||
@@ -554,6 +560,7 @@ export const productMutationTypeDefs = {
|
||||
visible,
|
||||
browsable,
|
||||
);
|
||||
await sendProductUpdatedEvent(productIds, ['product']); // Clears cache
|
||||
return {
|
||||
value: 'OK',
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user