You've waited for it, now it will wait for you.
The Job Scheduler allows you to schedule code to run at specified intervals. You schedule code to run by creating a job.
Each job defines what code to run and when to run it. The code your job runs can be any backend function. You can schedule that code to run on a daily, weekly, or monthly basis.
For example, you might create jobs that:
Import data from an external source once a day.
Delete collection data that is no longer relevant once a week.
Send a status report to relevant parties once a month.
How it works
You configure what jobs to run and when to run them in a jobs.config file in your site's backend.
The contents of the file look will look something like this:
{
"jobs": [
{
// first job object
"functionLocation": "/utils/dbUtils.js",
"functionName": "deleteExpired",
"description": "Delete expired DB items",
"executionConfig": {
"time": "22:00",
"dayOfWeek": "Sunday"
}
}, {
// another job object
}
]
}
For more information, see Scheduling Recurring Jobs.
Hey all,
Please note that we've updated the syntax for the jobs JSON to split the "functionLocation" into "functionLocation" and "functionName". See the updated syntax at the beginning of this thread.
Currently, the old configuration will work as well until the end of December, but you are encouraged to update to the new syntax.
I created jobs.config builder app: https://shoonia.github.io/jobs.config/ enjoy )))
Similary to @Naimi , I have a Job Scheduler setup, took out all the comments from the config file and haven't been able to get it to run.
Looking for tips.
jobs.config
{ "jobs": [ { "functionLocation": "/BodoDomkorApi/request.runJobs", "description": "Job to update all items in the database with concert bookings from the API at 10pm", "executionConfig": { "time": "22:00", } }, { "functionLocation": "/BodoDomkorApi/request.runJobs", "description": "Job to update all items in the database with concert bookings from the API", "executionConfig": { "time": "13:30", } }, { "functionLocation": "/BodoDomkorApi/request.runJobs", "description": "Job to update all items in the database with concert bookings from the API", "executionConfig": { "time": "06:20", } }, { "functionLocation": "/BodoDomkorApi/request.runJobs", "description": "Job to update all items in the database with concert bookings from the API at 10am", "executionConfig": { "time": "10:00" } } ] }
Folder Structure
Hi,
i tried to run job but with no success
i cant see any log on site monitoring event
{
"jobs": [
{
"functionLocation": "/utils/databaseJobs.test", //updateStoreItems
"description": "update paydb collection",
"executionConfig": {
"time": "17:20"
}
}
]
}
-----------------------------
//on databaseJobs.js=>
export function test() { console.log("Test Job Started"); }
Hi! I was wondering if Wix is planning on allowing more than 20 jobs configuration in the near or long future? Thank you! (cc: @Dmitry Batkilin )
If I want a job to run several timer a day can I add the times into 1 job or do I need to create another job object for each time I want the job to run. e.g
{ "jobs": [ { // first job object "functionLocation": "/utils/dbUtils.deleteExpired", "description": "Delete expired DB items", "executionConfig": { "time": "22:00", "time": "23.00" } }, { // another job object } ] }
Hey guys,
What are the duration limitations for the job scheduler functions? Can it run loop through a database of 100 items performing query and email triggers for each if necessary?
I have a chat system and I want to send out email notifications to people who did not 'SEE' the last message sent to them. In the database field 'status' if the value is 'UNSEEN' then I would like to trigger an email.
Its good for about 10-15 chats but what about more than 100? Can it fulfill all of them?
Shan
Hi Anthony
Then it sounds like a bug with the trigger in the jobs config file. Can you post a screenshot of your backend file locations as well as the jobs config code?
Thanks
Tiaan
@thomas.anthony
This looks very complex but it's actually quite simple. Think of the jobScheduler as a trigger, like a button would work. That's all it is. So the first step would be to create the backend file and write your function in there, something like this: (Oh yes, before you do this set up your file like I have here. Create a backend folder name 'utilities' and then under this create a .js file called 'cleanDB' - these are all just names I made up by the way but we need to reference it in the code)
Then in your 'cleanDB' folder add the following code:
export function removeEndDate() { let today = new Date(); wixData.query("posts") .lt("ends", today) .find() .then((results) => { if (results.items.length > 0) { let items = results.items; //loop through all the items and update the relevant ones items.forEach(item => { item.ends = undefined; wixData.update("posts", item) }); } }) .catch((err) => { let errorMsg = err; }); }
Then lastly set up your trigger in the jobScheduler backend file like so:
{ "jobs": [{ "functionLocation": "/utilities/cleanDB.removeEndDate", "description": "Remove expired end dates", "executionConfig": { "time": "15:31" //time is UCT time - allow 5 min's for function to run } }] }
Note in the above file the file location defined as "functionLocation" = "/utilities" is my folder, then "cleanDB" is my .js file and "removeEndDate" is my function name.
That's it! This should work if you just drop it in.
Good luck!
Tiaan
Hi Guys
I was wondering if anyone could help out - I'm struggling to wrap my head round this one!
I'm wanting to have a reoccurring code run every morning (any time, just needs to be daily) to check my database to see if the end date of a post has expired in one of my fields. If so, delete the 'end date' from the field (not the post - just the date in the field).
The database is called: "posts"
The field is called: "ends"
Is this feasible using job scheduler?
Many thanks in advance!
T.A
Invoking Web Module code from the job scheduler, are WebMethod requests still limited to 14 seconds?
Could someone like me make it to where something publishes to a database at a certain date and a certain time by adding some code to trigger the scheduler, so that at a certain time/date I can post let’s say a blog post
Hey Sam! I'm not being able to make this work. What am I missing? Time is UTC right?
// /backend/jobs.config { "jobs": [ { "functionLocation": "/utils/dbUtils.queryBlog", "description": "query blog daily for new articles. workaround while afterInsert hook gets implemented on Blog$Posts collection", "executionConfig": { "time": "03:18" //"dayOfWeek": String, // Optional: // Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday //"dateInMonth": Number // Optional: number between 1-31 } } ] }
I'm even using the same naming convention you are in the support article
The only thing I see different is I'm using a .js file (like the article says) but the picture in the article has a .jsw
Thoughts?
Any plans to make this scheduler more detailed? running hourly? on a minutes basis?
How do we know if there is an issue? Mine aren't running. The code works but maybe I didn't set it up right. Or is there like a wait period before they become active?
Can I logout a user who has been idle for x minutes or who has closed the browser without logging out?
A "pulse" in the log takes care of the former - what about the latter?
Thanks Sam, we needed that. May I congratulate you on having choses a config. file? If you ever make the date and time picker more flexible (translations of month, days, allowed dates, times-to-choose from in time), could you please also take this path? Saves you building user interfaces and we can use it for anything we´d like, how we like it.
Very helpful.
Backend functions are limited to 14 seconds of run time.
Does that limitation apply to jobs requested by this scheduler?
This is gonna help a lot, thanks wix
Amazing! Been waiting for this ofr a long time 😎