Back-end Code Example

Schedule

From the schedule.js node.js file:

'use strict'

const {SCHEDULE} = require('../configuration')

const schedule = require('node-schedule')
const every_six_minutes = '*/6 * * * *'
const every_seven_minutes = '*/7 * * * *'
const at_three_am = '0 3 * * *'
const every_twenty_minutes = '*/20 * * * *'
const first_day_of_month = '44 4 1 * *'
const at_five_pm = '0 17 * * *'

const process = props => {
    const {log, sql} = props

    if (SCHEDULE.processor) {
        const process = require('./schedule-processor')
        const job = schedule.scheduleJob(every_six_minutes, () => {
            process.process()
        })
        sql.add([log.info(`Scheduler for processor set to [${every_six_minutes}]`, job.name)])
    } else {
        sql.add([log.info(`Skipping scheduler for processor`)])
    }

    if (SCHEDULE.backup) {
        const process = require('./schedule-backup')
        const job = schedule.scheduleJob(at_three_am, () => {
            process.process()
        })
        sql.add([log.info(`Scheduler for backup set to [${at_three_am}]`, job.name)])
    } else {
        sql.add([log.info(`Skipping scheduler for backup`)])
    }

    if (SCHEDULE.vecozo) {
        const process = require('./schedule-vecozo')
        const job = schedule.scheduleJob(every_twenty_minutes, () => {
            process.process()
        })
        sql.add([log.info(`Scheduler for vecozo set to [${every_twenty_minutes}]`, job.name)])
    } else {
        sql.add([log.info(`Skipping scheduler for vecozo`)])
    }

    if (SCHEDULE.notification) {
        const process = require('./schedule-notification')
        const job = schedule.scheduleJob(every_six_minutes, () => {
            process.process()
        })
        sql.add([log.info(`Scheduler for notification set to [${every_six_minutes}]`, job.name)])
    } else {
        sql.add([log.info(`Skipping scheduler for notification`)])
    }

    if (SCHEDULE.daily_notification) {
        const process = require('./schedule-daily')
        const job = schedule.scheduleJob(at_five_pm, () => {
            process.process()
        })
        sql.add([log.info(`Scheduler for daily notification set to [${at_five_pm}]`, job.name)])
    } else {
        sql.add([log.info(`Skipping scheduler for daily notification`)])
    }

    if (SCHEDULE.statement) {
        const process = require('./schedule-statement')
        const job = schedule.scheduleJob(first_day_of_month, () => {
            process.process()
        })
        sql.add([log.info(`Scheduler for generating statements set to [${first_day_of_month}]`, job.name)])
    } else {
        sql.add([log.info(`Skipping scheduler for generating statements`)])
    }

    if (SCHEDULE.credit_invoice) {
        const process = require('./schedule-credit-invoice')
        const job = schedule.scheduleJob(every_seven_minutes, () => {
            process.process()
        })
        sql.add([log.info(`Scheduler for generating credit invoices set to [${every_seven_minutes}]`, job.name)])
    } else {
        sql.add([log.info(`Skipping scheduler for generating credit invoices`)])
    }
}

module.exports = process

Comments

You may also like:

Front-end Code Example

Color Toggle From the script.js file: /** * * @param {string} type: id, class or body * @param {string} value: element name * */ const element = function(type, value){ switch(type){...

Bachelor Back-end Development

In April 2020 I started a Bachelor in Back-end Development at Winc Academy, which focuses on Python, SQL and DevOps. Update: I succesfully finished the course in June! During the...