{"size": 815, "ext": "js", "max_stars_repo_path": "src/services/cron.js", "max_stars_repo_name": "ArielBetti/OwlWatch-API", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/services/cron.js", "max_issues_repo_name": "ArielBetti/OwlWatch-API", "max_issues_repo_issues_event_min_datetime": "2022-03-25T22:08:15.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T22:08:15.000Z", "max_forks_repo_path": "src/services/cron.js", "max_forks_repo_name": "ArielBetti/OwlWatch-API", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 27.1666666667, "max_line_length": 66, "alphanum_fraction": 0.5374233129}
const schedule = require('node-schedule');
const Alert = require('../models/Alert')
const searchEbay = require('../controllers/findItem');

function cron() {

    const twoMin = schedule.scheduleJob('*/2 * * * *', () => {
        SelectAlerts(2);
    });

    const tenMin = schedule.scheduleJob('*/10 * * * *', () => {
        SelectAlerts(10);
    });

    const thirtyMin = schedule.scheduleJob('*/30 * * * *', () => {
        SelectAlerts(30);
    });

    async function SelectAlerts(value) {
        const alert = await Alert.find({ "timer": value });
        for (let i = 0; i < alert.length; i++) {
            const key = alert[i].keyword;
            const mail = alert[i].email;
            const timer = alert[i].timer;
            searchEbay(key, mail, timer);
        }
    }
}

module.exports = cron;