Skip to content

Commit

Permalink
try timeout on build post
Browse files Browse the repository at this point in the history
  • Loading branch information
GraemeFulton committed Apr 19, 2024
1 parent 93468d3 commit 73491f9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
20 changes: 11 additions & 9 deletions pages/api/post/index-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
// import { processPost } from "@prototypr/prototypr-postie";
let processPost;

try {
const postie = await import("@prototypr/prototypr-postie");
processPost = postie.processPost;
} catch (error) {
processPost = () => {
// Provide a fallback implementation or handle the error appropriately
console.log("The @prototypr/prototypr-postie module is not public so was not instaled.");
};
}
(async () => {
try {
const postie = await import("@prototypr/prototypr-postie");
processPost = postie.processPost;
} catch (error) {
processPost = () => {
// Provide a fallback implementation or handle the error appropriately
console.log("The @prototypr/prototypr-postie module is not installed.");
};
}
})();

export const maxDuration = 120; // This function can run for a maximum of 120 seconds

Expand Down
38 changes: 27 additions & 11 deletions pages/post/[slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -446,19 +446,35 @@ export async function getStaticProps({ params, preview = null, locale }) {
}

export async function getStaticPaths({ locales }) {
const allPosts = await getAllPostsWithSlug(
"article",
process.env.NODE_ENV ||
process.env.NEXT_PUBLIC_HOME_URL.indexOf("localhost") > -1
? 20
: TOTAL_STATIC_POSTS

const timeout = (ms) => new Promise((resolve, reject) =>
setTimeout(() => reject(new Error('Request timed out')), ms)
);
// const homePosts = await getCombinedPostsForHomeStatic()

// let mergedSlugs = {
// ...allPosts,
// ...homePosts
// };
let allPosts=null
try {
allPosts = await Promise.race([
getAllPostsWithSlug(
"article",
process.env.NODE_ENV ||
process.env.NEXT_PUBLIC_HOME_URL.indexOf("localhost") > -1
? 20
: TOTAL_STATIC_POSTS
),
timeout(26000) // Set your desired timeout in milliseconds
]);
} catch (error) {
console.error(error);
// Handle the timeout error appropriately
}

// const allPosts = await getAllPostsWithSlug(
// "article",
// process.env.NODE_ENV ||
// process.env.NEXT_PUBLIC_HOME_URL.indexOf("localhost") > -1
// ? 20
// : TOTAL_STATIC_POSTS
// );

return {
paths:
Expand Down

0 comments on commit 73491f9

Please sign in to comment.