Schedule Recurring Jobs

You can create jobs to run any backend function and schedule them to run at specified, recurring intervals.

Before you begin

It's important to note the following before starting to code:

  • Scheduled jobs run with the permissions of the site administrator.
  • Free sites can add up to 3 scheduled jobs that run at a minimum of 1 hour intervals. If you need to add more jobs or run them more frequently, you can upgrade your site to a premium plan. Learn more about premium plans.
  • Depending on your plan you can add up to 30 jobs that run as frequently as one every 5 minutes.
  • All times in jobs are UTC time. To calculate the UTC equivalent of your local time, find your location's UTC time offset. Then either add or subtract to your local time based on the offset.

Step 1 | Add a backend function

The first step is to add a backend function that you want to run with a scheduled job. The function can be in any backend .js, .jsw or .web.js file.

Note: Make sure you export the function that you want the job scheduler to run.

Step 2 | Add jobs.config file in the backend.

  1. Go to the Public & Backend section of the Code sidebar.
  2. Hover over Backend, click the plus icon , and then click Add scheduled jobs.

Step 3 | Edit the JSON object to define the scheduled job

The jobs.config file contains a JSON object which defines all the scheduled jobs for your site. Each object in the jobs array contains the functionLocation, functionName, description, and executionConfig. Use the jobs JSON object reference for additional details on each field.

To simplify the process of building your jobs.config file, you can use this third-party Jobs Config tool. It allows you to enter the details of your jobs and builds the jobs object for you. The tool also includes a validator that can check your existing jobs.config file for errors.

Here is an example of a JSON object configured to send a status report every Monday morning at 8am UTC time:

Copy
1

Schedule multiple jobs

Schedule multiple jobs in your jobs.config file by adding additional objects to the jobs array.

Copy
1

Step 4 | Publish your site

You must publish your site to save changes to your scheduled jobs.

Troubleshooting your scheduled job

You can monitor the progress of a scheduled job with Wix Logs. If there is an error with the job syntax, it will display in Wix Logs when you publish your site. Additionally, if the function used in the job contains a console.log() then it will log to Wix Logs when it is called.

Connect Wix Logs to Google Cloud Logs, or another monitoring tool, so that you don't need to monitor the logs live as the jobs are triggered.

Was this helpful?
Yes
No