Let's take a look at an example of a scheduled job from our Give & Get site (template).
On our site, we use a scheduled job to remove giveaways that were either added or last updated over two months ago.
The job configuration looks like this:
1
As you can see the job is configured to call the removeOldGiveaways()
function from giveawaysModule.jsw once a day at 8:00 in the morning UTC time.
The removeOldGiveaways()
function looks like this:
1
We begin by calculating the date of the day that occurred two months ago.
1
Then, we find the giveaways that are older than two months old.
1
Next, we extract the IDs from the old giveaways. We need these to delete them.
1
Finally, we remove all the old giveaways using the bulk removal operation.
1