New Feature: Job Scheduler

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.

Thanks Wix You guys are Awesome!!!

Thank you guys!!! Keep exciting us with releases like these!!

Is there a video to demonstrate what function this is?

Amazing! Been waiting for this ofr a long time :sunglasses:

This is gonna help a lot, thanks wix

Very helpful.
Backend functions are limited to 14 seconds of run time.
Does that limitation apply to jobs requested by this scheduler?

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.

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?

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?

Any plans to make this scheduler more detailed? running hourly? on a minutes basis?

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?

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

Hi Felipe,

Thanks for the feedback, we may add this capability in future versions.
Currently you can use multiple jobs yo run the same function multiple times a day

Shlomi

Hi Patrick,
You can create a function in a test page to call you function in the backend. You can also create an http function (url) to call the same function in dev or live site.
For the schedule itself schedule your job to a minute in the future and publish your site, then update it to the schedule you actually need you
Can schedule your job to a minute in the future and publish your site, then update it to the schedule you actually need. In the next version we plan to create a simple wizard to help you with the json config file

Shlomi

Hi, can you please share a bit more about your intention?
I do not think we have this api at the moment, but this is a hood feedback

Shlomi

Hi Giri,

Your feedback sounds very interesting, can you please share more details? An example maybe?
The idea was to support something that resembles a chron expression in the future

Shlomi

Hi James,

Can you please share an example of what you would like to do? I am not sure i understand the question.

Thanks,
Shlomi

@shlomi-shemesh sure, what I want to accomplish is for users to schedule a story, a series, or a video, a story can be like a book, which I’ve successfully made functions that work as if you are reading a story like a book, but what I want to accomplish here is when users are busy, they can schedule their story, series, or video to come out at a specific date/time, kinda like YouTube.

Hey @james-rondon-jr ,

wow, sounds very interesting!
it seems like this new feature can be helpful, but i might also have an idea for you how to implement even without it. depends on the way you modeled your data and code flows.

for instance, you can let your users determine a point of time in the future in which their story/book should be published/available and then trigger a job every once in a while (few hours) to determine which of them should be published during this job’s time interval. it can be useful if you want to send your users an email, sharing with them newly published stories etc. in this case you anyway do not want to send such emails too frequently

another option is to use this future point in time determined by the users, to be kept in the db as an additional data point, and on your pages/searches showing the published list of stories always filter out those who are already published - ‘published date is before now’
you can also have a page of recently published stories, using this data - showing stories with published date in the past X days

hope i was able to help,
Shlomi