Send ProductUpdated SQS event for cache invalidation (#175)

This commit is contained in:
Fredrik Ringqvist
2025-06-13 15:28:39 +02:00
committed by GitHub
parent 39cd0e533e
commit f356ce0d4a
2 changed files with 23 additions and 0 deletions
+16
View File
@@ -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);
}
+7
View File
@@ -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',
};