imports/vx/server/daemon/daemon.js
/**
     * Dispatch any jobs whose wait interval has passed.
     */
Dispatch any jobs whose wait interval has passed.
Dispatch any jobs whose wait interval has passed .
conditionallyDispatch() {
        try {
            DaemonJobs.find({}).forEach(daemonJob => {
                const nowDate = new Date()
                if (daemonJob.nextDate <= nowDate) {
                    if (daemonJob.running) {
                        OLog.debug(`daemon.js conditionallyDispatch jobName=${daemonJob.jobName} already running *bypass*`)
                        return
                    }
                    if (daemonJob.timeUnit !== "SECOND") {
                        OLog.debug(`daemon.js conditionallyDispatch jobName=${daemonJob.jobName} ` +
                            `nextDate=${daemonJob.nextDate} nowDate=${nowDate}`)
                    }
                    const modifier = {}
                    modifier.$set = {}
                    modifier.$set.lastDate = nowDate
                    modifier.$set.nextDate = Util.computeNextDate(daemonJob.timeInterval, daemonJob.timeUnit,
                        daemonJob.timeOption, daemonJob.timezone, nowDate)
                    modifier.$set.running = true
                    DaemonJobs.update(daemonJob._id, modifier)
                    try {
                        const func = get(global, daemonJob.execFunctionName)
                        func(daemonJob)
                    }
                    catch (error) {
                        OLog.error(`daemon.js conditionallyDispatch unexpected error jobName=${daemonJob.jobName} ` +
                            `error=${error}`)
                    }
                    finally {
                        DaemonJobs.update(daemonJob._id, { $set: { running: false } })
                    }
                    if (daemonJob.timeUnit !== "SECOND") {
                        OLog.debug(`daemon.js conditionallyDispatch *finished* jobname=${daemonJob.jobName} ` +
                            `lastDate=${daemonJob.lastDate} nextDate=${daemonJob.nextDate}`)
                    }
                }
            })
        }
        catch (error) {
            OLog.error(`daemon.js conditionallyDispatch unexpected error=${error}`)
        }
    }
conditionallyDispatch ( ) { try { DaemonJobs . find ( { } ) . forEach ( daemonJob => { const nowDate = new Date ( ) if ( daemonJob . nextDate <= nowDate ) { if ( daemonJob . running ) { OLog . debug ( ` ${ daemonJob . jobName } ` ) return } if ( daemonJob . timeUnit !== "SECOND" ) { OLog . debug ( ` ${ daemonJob . jobName } ` + ` ${ daemonJob . nextDate } ${ nowDate } ` ) } const modifier = { } modifier . $set = { } modifier . $set . lastDate = nowDate modifier . $set . nextDate = Util . computeNextDate ( daemonJob . timeInterval , daemonJob . timeUnit , daemonJob . timeOption , daemonJob . timezone , nowDate ) modifier . $set . running = true DaemonJobs . update ( daemonJob . _id , modifier ) try { const func = get ( global , daemonJob . execFunctionName ) func ( daemonJob ) } catch ( error ) { OLog . error ( ` ${ daemonJob . jobName } ` + ` ${ error } ` ) } finally { DaemonJobs . update ( daemonJob . _id , { $set : { running : false } } ) } if ( daemonJob . timeUnit !== "SECOND" ) { OLog . debug ( ` ${ daemonJob . jobName } ` + ` ${ daemonJob . lastDate } ${ daemonJob . nextDate } ` ) } } } ) } catch ( error ) { OLog . error ( ` ${ error } ` ) } }
Dispatch any jobs whose wait interval has passed.
Dispatch any jobs whose wait interval has passed .