How to run scheduled jobs in Wix with Velo
Mosaddik Billah 2 min read

On this page
Some work should happen on its own: delete old form submissions every night, send a weekly summary, or sync prices from another system every morning. Velo has a built-in scheduler for this, configured in a file called jobs.config.
This guide sets up a nightly job that removes form submissions older than 90 days.
1. Write the function#
In the Velo sidebar, open the backend folder and create cleanup.js:
import wixData from "wix-data";
export async function deleteOldSubmissions() {
const cutoff = new Date();
cutoff.setDate(cutoff.getDate() - 90);
const result = await wixData
.query("Submissions")
.lt("_createdDate", cutoff)
.limit(1000)
.find({ suppressAuth: true });
if (result.items.length === 0) {
console.log("Cleanup: nothing to delete");
return;
}
const ids = result.items.map((item) => item._id);
await wixData.bulkRemove("Submissions", ids, { suppressAuth: true });
console.log(`Cleanup: deleted ${ids.length} old submissions`);
}Notes on this code:
suppressAuth: trueis needed because a scheduled job doesn’t run as a logged-in member.limit(1000)keeps each run to a manageable size. If you expect more than that per day, the next night’s run picks up the rest.- The
console.loglines show up in your site logs, so you can see what each run did.
2. Schedule it#
In the backend folder, create a file named exactly jobs.config:
{
"jobs": [
{
"functionLocation": "/cleanup.js",
"functionName": "deleteOldSubmissions",
"description": "Delete submissions older than 90 days",
"executionConfig": {
"cronExpression": "0 3 * * *"
}
}
]
}"0 3 * * *" means every day at 03:00. A few other examples:
"0 * * * *": every hour, on the hour"0 9 * * 1": every Monday at 09:00"30 6 1 * *": on the 1st of every month at 06:30
Times are in UTC, so adjust for your time zone. For example, 03:00 UTC is 09:00 in Bangladesh.
3. Publish and check#
Scheduled jobs only run on the published site, so publish after adding the file. After the first scheduled time has passed, open Developer Tools → Logs in your dashboard and look for the “Cleanup” messages.
To test without waiting, temporarily call deleteOldSubmissions() from a backend test function, or point it at a test collection first. Deleting data is permanent, so try it on test data before your real collection.
Things to keep in mind#
- Jobs can’t run more often than once an hour, and a site has a limit on how many jobs it can schedule.
- Keep each job short. Long-running jobs can be stopped, so split big tasks into smaller batches that run more often.
- Make jobs safe to run twice. If a run fails halfway, the next one should be able to continue without doing damage.
When to go further#
The same setup powers daily reports by email, reminders before a booking, syncing data from an external API, or archiving instead of deleting.
If you need automated tasks on your Wix site, I do Wix Velo development and custom API integrations.
Comments