async function sync() {
    log.debug(`Going for sync...`);
    try {
        // Get the current magister authcode before syncing users.
        let mAuth = await MagisterAuth();
        // Get all users from DB & run over them.
        let users = shuffleArray(await User.spot({isdisabled: false}).fetchAll());
        log.info(`Syncing ${users.length} users...`);
        for (let user of users) {
            try {
                // Log the user in.
                await user.login(oAuth, mAuth);
                // Fixy calendars (non - force).
                await user.setupCalendars();
                // Sync the actual appointments.
                await user.syncCalendars();
                // Wait some time (~0-5 seconds).
                await sleep(Math.floor(Math.random() * 5000));
            } catch(err) {
                try {
                    user.log.warn(`Error syncing user! `, {err: err.toString()});
                } catch(errr) {
                    log.error(`LOGGING ERROR! `, errr, {err: err.toString()});
                }
            }
        }
    } catch (err) {
        log.error(`MAJOR SYNC ERROR!`, err);
    }
    const next = scheduleTime();
    log.info(`Going for next sync in ${next} millis...`);
    setTimeout(sync, next);
}
/**
 * Main function of magbot.
 * This function calls itself to stay alive.
 */
Main function of magbot.
This function calls itself to stay alive.
Main function of magbot . This function calls itself to stay alive .
async function sync() {
    log.debug(`Going for sync...`);
    try {
        let mAuth = await MagisterAuth();
        let users = shuffleArray(await User.spot({isdisabled: false}).fetchAll());
        log.info(`Syncing ${users.length} users...`);
        for (let user of users) {
            try {
                await user.login(oAuth, mAuth);
                await user.setupCalendars();
                await user.syncCalendars();
                await sleep(Math.floor(Math.random() * 5000));
            } catch(err) {
                try {
                    user.log.warn(`Error syncing user! `, {err: err.toString()});
                } catch(errr) {
                    log.error(`LOGGING ERROR! `, errr, {err: err.toString()});
                }
            }
        }
    } catch (err) {
        log.error(`MAJOR SYNC ERROR!`, err);
    }
    const next = scheduleTime();
    log.info(`Going for next sync in ${next} millis...`);
    setTimeout(sync, next);
}
async function sync ( ) { log . debug ( ` ` ) ; try { let mAuth = await MagisterAuth ( ) ; let users = shuffleArray ( await User . spot ( { isdisabled : false } ) . fetchAll ( ) ) ; log . info ( ` ${ users . length } ` ) ; for ( let user of users ) { try { await user . login ( oAuth , mAuth ) ; await user . setupCalendars ( ) ; await user . syncCalendars ( ) ; await sleep ( Math . floor ( Math . random ( ) * 5000 ) ) ; } catch ( err ) { try { user . log . warn ( ` ` , { err : err . toString ( ) } ) ; } catch ( errr ) { log . error ( ` ` , errr , { err : err . toString ( ) } ) ; } } } } catch ( err ) { log . error ( ` ` , err ) ; } const next = scheduleTime ( ) ; log . info ( ` ${ next } ` ) ; setTimeout ( sync , next ) ; }
Main function of magbot.
Main function of magbot .
// Get the current magister authcode before syncing users. // Get all users from DB & run over them. // Log the user in. // Fixy calendars (non - force). // Sync the actual appointments. // Wait some time (~0-5 seconds).