<commit_before>// Cron.js - in api/services

"use strict";
const CronJob = require('cron').CronJob;

const crons = [];

module.exports = {
    start: () => {
        sails.config.scientilla.crons.forEach(cron =>
            crons.push(new CronJob(cron.time, generateOnTick(cron), onStop, false, 'Europe/Rome'))
        );
        crons.forEach(cron => cron.start());
    },
    stop: () => {
        crons.forEach(cron => cron.stop());
    }
};

function generateOnTick(cron) {
    return async function () {
        if (!cron.enabled)
            return;

        sails.log.info('Cron ' + cron.name + ' started at ' + new Date().toISOString());

        for (const job of cron.jobs) {
            try {
                await _.get(global, job.fn)(...job.params);
            } catch (e) {
                sails.log.error(e);
            }
        }

        sails.log.info('Cron ' + cron.name + ' finished at ' + new Date().toISOString());
    }
}

function onStop() {

}<commit_msg>Added lodash require<commit_after>// Cron.js - in api/services

"use strict";
const CronJob = require('cron').CronJob;
const _ = require('lodash');

const crons = [];

module.exports = {
    start: () => {
        sails.config.scientilla.crons.forEach(cron =>
            crons.push(new CronJob(cron.time, generateOnTick(cron), onStop, false, 'Europe/Rome'))
        );
        crons.forEach(cron => cron.start());
    },
    stop: () => {
        crons.forEach(cron => cron.stop());
    }
};

function generateOnTick(cron) {
    return async function () {
        if (!cron.enabled)
            return;

        sails.log.info('Cron ' + cron.name + ' started at ' + new Date().toISOString());

        for (const job of cron.jobs) {
            try {
                await _.get(global, job.fn)(...job.params);
            } catch (e) {
                sails.log.error(e);
            }
        }

        sails.log.info('Cron ' + cron.name + ' finished at ' + new Date().toISOString());
    }
}

function onStop() {

}
{'fraction_non_alphanumeric': 0.16766467065868262, 'fraction_numerical': 0.0, 'mean_word_length': 1.9615952732644018, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2316239', 'n_tokens_mistral': 680, 'n_tokens_neox': 649, 'n_words': 122}