Leaving a little mini tutorial here for setting up cron jobs on Render.com.
I expected that I would be able to click a button, have some kind of UI where I could schedule hitting a function on my API install. This was not the case. Here we go…
Make a script
First up in redwood, we will make a script - Instructions here
Redwood will make a file in the scripts folder and give you some handy boiler plate to, say write a prisma query. In my case I wanted to use a service I had created. Here is an example:
import { createReport } from 'api/src/services/reports/reports'
export default async () => {
const reportData = await createReport()
console.log(':: Executing report', reportData)
return reportData
}
Making a cron job in render
Next up we are going to
- Go to our Render.com dashboard, click the “New” button and select cron job
- Connect your full repo for your redwood install
- Give it a name, you can skip a few settings, and then select you branch
- For your build command enter ‘yarn && yarn rw build api’
- Pick a schedule as needed
- And finally in the command field you will run the script as documented here. In my case that looked like ''yarn redwood exec monthlyReportRunner"
That’s it! It felt quite odd having to connect my whole repo, put in build details etc, but that is what ya gotta do.
Got a better way to do it? Leave it in the comments.
Have a great day