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

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

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

Copy

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

Copy

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

Copy

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

Copy
Was this helpful?
Yes
No