I have added a jobs.config under backend with this code:
{
“jobs”: [
{
“functionLocation”: “/xxx.jsw”, // Relatively to Backend folder, started by slash
“functionName”: “xxxMethod”,
“description”: “xxx description”, // Optional
“executionConfig”: {
“cronExpression”: “0 30 0/1 ? * * *” // Set intervals of up to 1 hour
// Read about Cron expressions: [[cron - Wikipedia]]([cron - Wikipedia]
}
}
]
})
[}]([cron - Wikipedia]
}
}
]
})
[}]([cron - Wikipedia]
}
}
]
})
]([cron - Wikipedia]
}
}
]
})
[}]([cron - Wikipedia]
}
}
]
})
And under backend/xxx.jsw, I have added the method as following:
export function xxxMethod() {
//it does more than just console.log. this is just to describe what i did
console.log(“in method”);
}
I haven’t seen the task get executed as site monitoring doesn’t show any logs. Can someone please help me understand what I am doing wrong or where to look for errors.
Thanks,
Babar
Hello.
You should make sure that the time is specified as UTC time in HH:MM format. You can convert your local time to UTC time by googling the conversion.
Once corrected the job will run within 5 minutes after the specified time.
Good luck!
Hi Sam,
The cron schedule above should run every hour. there is no time specified in there.
Thanks,
Babar
If you read the Wix pages about Job Scheduler then you will see that Sam is correct.
https://support.wix.com/en/article/corvid-scheduling-recurring-jobs
Time (String)
The time of day the job runs. The time is specified as UTC time in HH:MM format.
Therefore any time that you set in the Cron will be in that UTC time format.
executionConfig (Object)
An object containing information about when the job should run. You can define when the job runs using a cron expression or by specifying a time of day and optionally a day of the week or date in the month.
Important:
-
Jobs occuring more than once a day must be defined using a cron expression.
-
If both specifications exist for a single job, only the cron expression will be used.
Cron Expression
When using a cron expression to specify when a job runs, the “executionConfig” object contains a single property, named “cronExpression”, whose value is a valid cron expression.
cronExpression (String)
A valid cron expression . For example, to run a job every day at 8:00 in the morning, use:
"cronExpression": "0 8 * * *"
Important:
When using a cron expression, you can schedule your job to run at intervals as short as one hour apart, but not shorter. If you define your job to run more frequently, the job will be ignored.
I seem to get a different expression at each CRON expression builder site that I visit. In the end this “cronExpression” : “0 * * * *” seems to be parsing without errors
In case anyone comes across this and hasn’t found an answer. Some things that i think were tripping me up.
- seems like the page needs to be published for the changes to work
- the script name can only have letters. I was using an underscore and seemed like this affected it.
- the js file needed all the parts below
- output the time in javscript with the code below to check what time your job should shedule (check against your own time and set the job to activate 2 mins before the current time to test):
var d = new Date();
console.log(d.toLocaleTimeString());
my final working jobs config code. runs every hour:
{
"jobs": [
{
"functionLocation": "/binance/binance.start",
"executionConfig": {
"cronExpression": "0 * * * *"
}
}
]
}
the js file located at the backend/binance/binance.js has the following that seem to be needed:
export function start() {
// do your stuff here
}
/*
$w.onReady(function () {
start();
});
*/