<commit_before>var async = require( "async" );
var moment = require( "moment" );
var config = require( "./lib/configuration" );
var connections = require( "./lib/connections" );
var models = require( "./lib/models" );


var logger = connections.logger( config.systemReadingLogglyTag );
var db = connections.database();
var broker = connections.jackrabbit();

broker.once( "connected", createQueue );


function createQueue () {
    broker.create( config.systemQueue, run );
}


function run () {
    var previousMinute;
    setInterval( function () {
        var currentMinute = moment().minutes();
        if ( previousMinute !== currentMinute && currentMinute % config.systemReadingMinute === 0 ) {
            previousMinute = currentMinute;
            processSystemReading();
        }
    }, config.runInterval );
}


function processSystemReading () {
    async.waterfall( [ readSystem, saveData ], function ( err, result ) {
        if ( err ) {
            logger.log( err );
            process.exit( 1 );
        }
        console.log( result );
    } );
}


function readSystem ( done ) {
    broker.publish( config.systemQueue, {}, function ( err, data ) {
        if ( err ) {
            return done( err );
        }
        return done( null, data );
    } );
}


function saveData ( systemData, done ) {
    models.SystemReading.add( systemData, function ( err, data ) {
        if ( err ) {
            return done( err );
        }
        return done( null, data );
    } );
}<commit_msg>Organize script<commit_after>var async = require( "async" );
var moment = require( "moment" );
var throng = require( "throng" );
var config = require( "./lib/configuration" );
var connections = require( "./lib/connections" );
var models = require( "./lib/models" );


function main () {
    var logger = connections.logger( config.systemReadingLogglyTag );
    var db = connections.database();
    var broker = connections.jackrabbit();

    broker.once( "connected", createQueue );


    function createQueue () {
        broker.create( config.systemQueue, run );
    }


    function run () {
        var previousMinute;
        setInterval( function () {
            var currentMinute = moment().minutes();
            if ( previousMinute !== currentMinute && currentMinute % config.systemReadingMinute === 0 ) {
                previousMinute = currentMinute;
                processSystemReading();
            }
        }, config.runInterval );
    }


    function processSystemReading () {
        async.waterfall( [ readSystem, saveData ], function ( err, result ) {
            if ( err ) {
                logger.log( err );
                process.exit( 1 );
            }
            console.log( result );
        } );
    }


    function readSystem ( done ) {
        broker.publish( config.systemQueue, {}, function ( err, data ) {
            if ( err ) {
                return done( err );
            }
            return done( null, data );
        } );
    }


    function saveData ( systemData, done ) {
        models.SystemReading.add( systemData, function ( err, data ) {
            if ( err ) {
                return done( err );
            }
            return done( null, data );
        } );
    }
}


if ( require.main === module ) {
    if ( config.debugMode ) {
        console.log( "Running in debug mode..." );
        main();
    } else {
        throng( main, {
            workers: 1,
            lifetime: Infinity
        } );
    }
}
{'fraction_non_alphanumeric': 0.1301605504587156, 'fraction_numerical': 0.0014334862385321102, 'mean_word_length': 1.9871575342465753, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7009743', 'n_tokens_mistral': 970, 'n_tokens_neox': 927, 'n_words': 241}