Give & Get Example - Scheduling Jobs

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:

Copy
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:

Copy
1

We begin by calculating the date of the day that occurred two months ago. 

Copy
1

Then, we find the giveaways that are older than two months old.

Copy
1

Next, we extract the IDs from the old giveaways. We need these to delete them.

Copy
1

Finally, we remove all the old giveaways using the bulk removal operation.

Copy
1
Was this helpful?
Yes
No