Implementing a cron job on Blitz is not different than on Next.js.
First of all you have to define your serverless function, under the /api
folder (at the root, not in the rpc
folder).
Then, create your file, such as:
import { api } from "app/blitz-server"
import db from "db"
export default api(async (req, res, ctx) => {
try {
// Do something here
res.status(200).json({
message: `Success!`,
})
} catch (e) {
res.status(400).json({
message: `Error : ${e.message}`,
})
}
})
Finally, you just need to create a cron job that target your api route.
For this, you have several free options:
Otherwise, you have many third party options, but not always free.
Hope this helps