Scheduling Recurring AI Batch Jobs on a VPS
This article covers designing batch jobs on a VPS, such as having the AI process things in bulk every night, and building a mechanism that lets you notice when a job fails partway.
Ren

Procura
When batch jobs are a good fit
- Work that doesn't need an immediate result
- Work that is more efficient in bulk (handing over many items together is sometimes faster than calling one by one)
- Work whose load you want to place in hours when few users are around

Ren

Procura
A way to notice failures
You can't notice right away when a job that runs at night fails. Finding out in the morning that last night's job didn't run is too late, and you'd only learn of it after users are affected. Build in from the start a mechanism that always records whether a job succeeded or failed and sends a notification when it fails.
- Record the start, the end, and whether the job succeeded or failed
- Make sure a notification reaches the person in charge when it fails
- Make it possible to notice when a job is taking longer than expected
Cautions specific to calling AI
When a batch job calls AI in large volume, even if each call costs little, the total can become a significant amount when the number of items is large. Before you start, estimate the rough total from the number of items and the cost per item, and check that it hasn't grown beyond what you expected.

Ren

Procura
Preventing duplicate runs
Another accident that tends to happen with batch jobs is that the next scheduled time arrives while the previous day's job is still unfinished, and a new job starts a second time. When the same job runs twice at once, results get duplicated and calls to the AI increase needlessly. Make sure the next job starts only after confirming the previous one has finished, or add a mechanism that allows only one to run at a time.
- Start the next job only after checking that the previous one has finished
- Add a control that prevents duplicate runs so the same job doesn't run several times at once
- If the processing time keeps growing, take particular care that it doesn't overlap with the next run

Procura

Ren
This article is translated from the Japanese original. If the two differ, the Japanese version is the one we keep up to date.