edgaras
edgaras
Explore posts from servers
TTCTheo's Typesafe Cult
Created by edgaras on 1/11/2024 in #questions
Pre-rendered page + dynamic content
I found a way with Next.js unstable_cache So I keep whole route dynamic, but I cache publicArticles instead:
export default async function ArticlesPage() {
const getCachedPublicArticles = unstable_cache(
// Cache public articles
async () => getPublicArticles(),
['articles'],
{
revalidate: 30, // for 30 seconds
},
)
const publicArticles = (await getCachedPublicArticles()) ?? []

const user = await getUser()
const articles = user
? [...publicArticles, ...((await getDraftArticles()) ?? [])] // If user is logged in, mix public and draft articles
: publicArticles // Otherwise, only show public articles
export default async function ArticlesPage() {
const getCachedPublicArticles = unstable_cache(
// Cache public articles
async () => getPublicArticles(),
['articles'],
{
revalidate: 30, // for 30 seconds
},
)
const publicArticles = (await getCachedPublicArticles()) ?? []

const user = await getUser()
const articles = user
? [...publicArticles, ...((await getDraftArticles()) ?? [])] // If user is logged in, mix public and draft articles
: publicArticles // Otherwise, only show public articles
3 replies
TTCTheo's Typesafe Cult
Created by edgaras on 8/8/2023 in #questions
Does API function timeout if it’s triggered by multiple cron jobs?
Well, I will be calling my Postgres db on every call, checking for unsent emails and then after successfully sending, marking every user row as sent. So should be fine even if some of them fails. Failed ones will be retried on other calls.
37 replies
TTCTheo's Typesafe Cult
Created by edgaras on 8/8/2023 in #questions
Does API function timeout if it’s triggered by multiple cron jobs?
Here you call the functions without requiring to return a response right?
37 replies
TTCTheo's Typesafe Cult
Created by edgaras on 8/8/2023 in #questions
Does API function timeout if it’s triggered by multiple cron jobs?
So Vercel Cron + multiple serverless function triggers was my last hope before getting to something like Qstash, or running a separate node.js app in VPS…
37 replies
TTCTheo's Typesafe Cult
Created by edgaras on 8/8/2023 in #questions
Does API function timeout if it’s triggered by multiple cron jobs?
Yeah… I know. I would just like to keep it all in one code base. Just to send this newsletter now I have to start VPS, maintain it etc.). I rather have something that is hacky and works but in the same Next.js codebase.
37 replies
TTCTheo's Typesafe Cult
Created by edgaras on 8/8/2023 in #questions
Does API function timeout if it’s triggered by multiple cron jobs?
Thnx I will try looking into it! Long running jobs in Vercel/Next are not very well documented…
37 replies
TTCTheo's Typesafe Cult
Created by edgaras on 8/8/2023 in #questions
Does API function timeout if it’s triggered by multiple cron jobs?
The reason I am asking because I was confused about a warm lambda, if it will try to use the same one for same job cuz it’s warm, and eventually timeout. Need to test that. On localhost the response time was adding up for some reason, the more I was calling same function. But I was testing it recursively, maybe that’s why
37 replies
TTCTheo's Typesafe Cult
Created by edgaras on 8/8/2023 in #questions
Does API function timeout if it’s triggered by multiple cron jobs?
Yes but it says better run 30-60 secs. And generally lambdas are made to run up to a few secs max
37 replies
TTCTheo's Typesafe Cult
Created by edgaras on 8/8/2023 in #questions
Does API function timeout if it’s triggered by multiple cron jobs?
I will try to batch a bit also. Resend can send 10emails a second, so I can send around 200 emails in 30 sec in a serverless function
37 replies
TTCTheo's Typesafe Cult
Created by edgaras on 8/8/2023 in #questions
Does API function timeout if it’s triggered by multiple cron jobs?
Definitely. I am still not sure this is the best way to do this in serverless
37 replies
TTCTheo's Typesafe Cult
Created by edgaras on 8/8/2023 in #questions
Does API function timeout if it’s triggered by multiple cron jobs?
Yeah but once it’s warm, wouldn’t it try using the same warm lambda? And then eventually timeout?
37 replies
TTCTheo's Typesafe Cult
Created by edgaras on 8/8/2023 in #questions
Does API function timeout if it’s triggered by multiple cron jobs?
Myeah. But there is something about warm/cold lambda
37 replies
TTCTheo's Typesafe Cult
Created by 0sir1s on 8/6/2023 in #questions
How would I go about using Cloudflare R2
One thing I discovered recently R2 doesn’t have versioning, while S3 does. But I am on R2 now.
7 replies