Schedule more then 20 jobs to update collections everyday

Hi all,

I am trying to schedule more then 20 jobs to run my code at the same time every day. My code gets data from an api endpoint and inserts it into a collection. The problem is that the job scheduler wix provides can’t update all my collections. I need an alternative job scheduler. I am currently trying to use bree npm module to do it but I don’t understand how to use it on my own.

Here is the code that needs to be scheduled to run every day all at the same time. I plan on eventually having hundreds of these updating my collections. And I will get lots of search traffic from google when the site is complete. the way I have it now I just use 1 collection per site. the problem with this is I would eventually have to pay for premium plans for lots of websites. I decided I need hundreds of collections of the one website and I will pay for premium for that site. Here is my current website https://affiliatesupermarket.wixsite.com/affxsup

Ignore:
@shantanukumar847

'use strict';

import { fetch } from 'wix-fetch';

const url1 = 'https://sheets.googleapis.com/v4/spreadsheets/1rDoA3Zmauec4TAE_2hgu_hJAqrv97DXB41QUyj0iBAU/values/wixcollection1?key=AIzaSyBqo6jSdlT3hMNnWgprLOH9O6hDB7DjBqk'; //tooled up

/*

$$\      $$\           $$\                  $$$$$$\                                      
$$$\    $$$ |          \__|                $$  __$$\                                     
$$$$\  $$$$ | $$$$$$\  $$\ $$$$$$$\        $$ /  \__|$$\   $$\ $$$$$$$\   $$$$$$$\       
$$\$$\$$ $$ | \____$$\ $$ |$$  __$$\       $$$$\     $$ |  $$ |$$  __$$\ $$  _____|      
$$ \$$$  $$ | $$$$$$$ |$$ |$$ |  $$ |      $$  _|    $$ |  $$ |$$ |  $$ |$$ /            
$$ |\$  /$$ |$$  __$$ |$$ |$$ |  $$ |      $$ |      $$ |  $$ |$$ |  $$ |$$ |            
$$ | \_/ $$ |\$$$$$$$ |$$ |$$ |  $$ |      $$ |      \$$$$$$  |$$ |  $$ |\$$$$$$$\       
\__|     \__| \_______|\__|\__|  \__|      \__|       \______/ \__|  \__| \_______| 

*/

import _ from 'lodash';

export async function insertData1() {

    return wixData.truncate('tooledup')

    .then (() => {

        console.log('cleared')

        return fetchData(url1)

        .then(async data => {

            let formatted = formatData(data.values);

            console.log(formatted.length)

            const insertableArrays = _.chunk(formatted, 1000);

            for ( let insertableArray = 0; insertableArray < insertableArrays.length; insertableArray++ ) {

                await wixData.bulkInsert('tooledup',insertableArrays[insertableArray])

            }   

        })

    })
}

export async function fetchData(url) {

    return fetch(url, {"method": "get"})

    .then( (httpResponse) => {

        if (httpResponse.ok) {

            return httpResponse.json();

        }

    })

    .catch(err => {

        return err;
    
    });

}

import wixData from 'wix-data';

export function formatData(data) {

    let keys = data[0];

    let bulk = [];

    for ( let value = 1; value < data.length ; value++ ) {

        let obj = {};

        for ( let key = 0; key < keys.length -1 ; key++) {
            
            obj[keys[key]] = data[value][key];

        }

        bulk.push(obj);
    
    }

    return bulk;

    // Promise.resolve(bulk)

}

Are they all updating at the same time of the day, or will they be updated at different times?

I want all of the jobs to run at the same time of day.

Ok, it’s not really a problem then. What you want to do is make one function that runs all the other ones

function getData(){
getFromSiteOne();
getFromSiteTwo();
getFromSiteTwo();
}

Then just run getData() in the jobs scheduler instead of each function individually

@simen thanks it worked!