I'm a bit confused where Nitro hangs out in the deployment space and how these deployed environments manage setInterval alongside Nitro endpoints.
I have a function that runs every 10 seconds and is currently managed in Nitro like so:
export default defineEventHandler(async event => {
try {
let intervalId: NodeJS.Timeout
const intervalTime = 10000 // 10 seconds in milliseconds
intervalId = setInterval(() => {
getLiveGameData(intervalId)
}, intervalTime)
} catch (e) {
const error = createError({
statusCode: 500,
statusMessage: `Something went wrong with lolesports: ${e}`,
})
return sendError(event, error)
}
})
Does this run for a few seconds every interval, or is the setInterval creating a long-running process that is never killed until the setInterval is killed using clearInterval(intervalId)?
I imagine the latter would get expensive quickly in a serverless environment. Or, am I overthinking this?
My understanding is serverless is ideal for short-running bits of code, not for long-running processes, and in fact, serverless providers tend to have a time-limit on long-running code. Is there a more ideal way to deploy a Nuxt application that utilizes Nitro extensively and doesn't depend on a serverless backend?