Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cache update on product webhooks #1036

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/breezy-carrots-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-app-products-feed": patch
---

Removed webhooks on product changes used for feed cache due to changed max execution time.
5 changes: 5 additions & 0 deletions .changeset/tender-seas-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-app-products-feed": patch
---

Changed Vercel's maximum execution time to be 5 minutes for feed generation. This should help with the previous limits of 60s, that was not enough for feed to be generated.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

9 changes: 7 additions & 2 deletions apps/products-feed/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ const isSentryPropertiesInEnvironment =
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
transpilePackages: ["@saleor/apps-shared", "@saleor/apps-ui", "@saleor/react-hook-form-macaw"],
transpilePackages: [
"@saleor/apps-shared",
"@saleor/apps-ui",
"@saleor/react-hook-form-macaw",
"@saleor/webhook-utils",
],
};

const configWithSentry = withSentryConfig(
Expand All @@ -22,7 +27,7 @@ const configWithSentry = withSentryConfig(
tunnelRoute: "/monitoring",
hideSourceMaps: true,
disableLogger: true,
}
},
);

module.exports = isSentryPropertiesInEnvironment ? configWithSentry : nextConfig;
2 changes: 2 additions & 0 deletions apps/products-feed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@saleor/apps-ui": "workspace:*",
"@saleor/macaw-ui": "0.8.0-pre.127",
"@saleor/react-hook-form-macaw": "workspace:*",
"@saleor/webhook-utils": "workspace:*",
"@sentry/nextjs": "7.67.0",
"@tanstack/react-query": "4.29.19",
"@trpc/client": "10.38.1",
Expand All @@ -27,6 +28,7 @@
"@trpc/server": "10.38.1",
"@urql/exchange-auth": "^2.1.4",
"@vitejs/plugin-react": "4.0.4",
"dotenv": "^16.3.1",
"fast-xml-parser": "^4.0.15",
"graphql": "16.7.1",
"graphql-tag": "^2.12.6",
Expand Down
7 changes: 7 additions & 0 deletions apps/products-feed/scripts/migrations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Webhook migration scripts

Test migration with dry run, operation will not modify any data:
`npx tsx scripts/migrations/run-webhooks-migration-dry-run.ts`

To start the migration run command:
`npx tsx scripts/migrations/run-webhooks-migration.ts`
20 changes: 20 additions & 0 deletions apps/products-feed/scripts/migrations/migration-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-disable turbo/no-undeclared-env-vars */

import { SaleorCloudAPL } from "@saleor/app-sdk/APL";

export const verifyRequiredEnvs = () => {
const requiredEnvs = ["SALEOR_CLOUD_TOKEN", "SALEOR_CLOUD_RESOURCE_URL"];

if (!requiredEnvs.every((env) => process.env[env])) {
throw new Error(`Missing envs: ${requiredEnvs.join(" | ")}`);
}
};

export const fetchCloudAplEnvs = () => {
const saleorAPL = new SaleorCloudAPL({
token: process.env.SALEOR_CLOUD_TOKEN!,
resourceUrl: process.env.SALEOR_CLOUD_RESOURCE_URL!,
});

return saleorAPL.getAll();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* eslint-disable turbo/no-undeclared-env-vars */

import * as dotenv from "dotenv";
import { fetchCloudAplEnvs, verifyRequiredEnvs } from "./migration-utils";
import { updateWebhooksScript } from "./update-webhooks";

dotenv.config();

const runMigration = async () => {
console.log("Starting webhooks migration (dry run)");

verifyRequiredEnvs();

console.log("Envs verified, fetching envs");

const allEnvs = await fetchCloudAplEnvs().catch((r) => {
console.error("Could not fetch instances from the APL");
console.error(r);

process.exit(1);
});

for (const env of allEnvs) {
await updateWebhooksScript({ authData: env, dryRun: true });
}

console.log("Migration dry run complete");
};

runMigration();
30 changes: 30 additions & 0 deletions apps/products-feed/scripts/migrations/run-webhooks-migration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* eslint-disable turbo/no-undeclared-env-vars */

import * as dotenv from "dotenv";
import { fetchCloudAplEnvs, verifyRequiredEnvs } from "./migration-utils";
import { updateWebhooksScript } from "./update-webhooks";

dotenv.config();

const runMigration = async () => {
console.log("Starting running migration");

verifyRequiredEnvs();

console.log("Envs verified, fetching envs");

const allEnvs = await fetchCloudAplEnvs().catch((r) => {
console.error("Could not fetch instances from the APL");
console.error(r);

process.exit(1);
});

for (const env of allEnvs) {
await updateWebhooksScript({ authData: env, dryRun: false });
}

console.log("Migration complete");
};

runMigration();
29 changes: 29 additions & 0 deletions apps/products-feed/scripts/migrations/update-webhooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* eslint-disable turbo/no-undeclared-env-vars */

import { createGraphQLClient } from "@saleor/apps-shared";
import { AuthData } from "@saleor/app-sdk/APL";
import { webhookMigrationRunner } from "@saleor/webhook-utils";

export const updateWebhooksScript = async ({
authData,
dryRun,
}: {
authData: AuthData;
dryRun: boolean;
}) => {
console.log("Working on env: ", authData.saleorApiUrl);

const client = createGraphQLClient({
saleorApiUrl: authData.saleorApiUrl,
token: authData.token,
});

await webhookMigrationRunner({
client,
dryRun,
getManifests: async ({ appDetails }) => {
// Products feed application has currently no webhooks, so we return empty array
return [];
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { router } from "../trpc/trpc-server";
import { protectedClientProcedure } from "../trpc/protected-client-procedure";
import { createLogger } from "@saleor/apps-shared";

import { updateCacheForConfigurations } from "../metadata-cache/update-cache-for-configurations";
import { AppConfigSchema, imageSizeInputSchema, titleTemplateInputSchema } from "./app-config";
import { z } from "zod";
import { createS3ClientFromConfiguration } from "../file-storage/s3/create-s3-client-from-configuration";
Expand Down Expand Up @@ -106,17 +105,6 @@ export const appConfigurationRouter = router({
}) => {
const config = await getConfig();

/**
* TODO Check if this has to run, once its cached, it should be invalidated by webhooks only.
*
* But this operation isn't expensive and users will not continuously save this form
*/
await updateCacheForConfigurations({
client: apiClient,
channelsSlugs: [input.channelSlug],
saleorApiUrl: saleorApiUrl,
});

logger.debug({ channel: input.channelSlug }, "Updated cache for channel");

config.setChannelUrls(input.channelSlug, input.urls);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading