Timed tasks by week - cleaning database of old listings

I’ve watched the video on how to schedule a timed task to clean old [listings.](listings.

https://www.wix.com/corvid/forum/tips-tutorials-examples/video-how-to-execute-timed-tasks-with-the-job-scheduler)
However this is set to occur every 3 months and I want to have this happen weekly.

https://www.sloungebar.com.au/gigguidetest
Any help appreciated as I can’t seem to get this to happen weekly.
Thank you

BACKEND MODULE
import wixData from ‘wix-data’ ;

export function clearOldListings() {
// Querying all the items in the collection.
return wixData.query( “GigList” ).find().then(results => {
// Declaring a variable for an expiration date to test by initiating it as a date object.
let expirationDate = new Date();
// Setting the expiration date for 3 months prior.
expirationDate.setWeek(expirationDate.getWeek() - 1 );
// Using the forEach method to create a filtered array with listings older than 3 months.
let oldListings = results.items.filter(item => item.uploadedOn < expirationDate);
oldListings.forEach(item => {
// Removing each of this items from the collection.
wixData.remove( “GigList” , item._id);
})
})
}

JOB SCHEDULER
{
“jobs” : [{
“functionLocation” : “/DatabaseJobs.clearOldListings” ,
“description” : “Clear Weekly-onMonday” ,
“executionConfig” : {
“time” : “20:40” ,
“dayOfWeek” : Sunday
}
}
]
}

  1. In the job.config file you need to write “Sunday” with quotes.

  2. On the clearOldListings, the default limit is 50 records. If you want more, you need to add .limit(1000) if you need more than 1000 records, you’ll have to iterate.

  3. the order you do things is not ideal. You’re better query the old records from the beginning (in the query itself).

Hi JD. Appreciate the response. I’ve tried putting Sunday in “” (now Monday to test) and it’s still not working. I’m not much of a master with coding so was just working with the code offered with the video explanation by Wix.

Any help appreciated…or point me in the right direction of a better tut vid.

V kindly
Luke