{"size": 1591, "ext": "js", "max_stars_repo_path": "client/index.js", "max_stars_repo_name": "insanity54/mc-screenshot-twitter", "max_stars_repo_stars_event_min_datetime": "2015-12-07T07:40:19.000Z", "max_stars_repo_stars_event_max_datetime": "2015-12-07T07:40:19.000Z", "max_issues_repo_path": "client/index.js", "max_issues_repo_name": "insanity54/mc-screenshot-twitter", "max_issues_repo_issues_event_min_datetime": "2018-10-05T03:38:22.000Z", "max_issues_repo_issues_event_max_datetime": "2018-10-05T03:38:22.000Z", "max_forks_repo_path": "client/index.js", "max_forks_repo_name": "insanity54/mc-screenshot-twitter", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 34.5869565217, "max_line_length": 131, "alphanum_fraction": 0.666247643}
var path = require('path');
var async = require('async');
var assert = require('chai').assert;
var redis = require('redis');
var nconf = require('nconf');
var Worker = require(path.join(__dirname, 'worker'));
var auth = require(path.join(__dirname, 'auth'));
var minecraft = require(path.join(__dirname, 'minecraft'));
var input = require(path.join(__dirname, 'input'));
var util = require(path.join(__dirname, 'util'));

nconf.file(path.join(__dirname, '..', 'config.json'));


var redisOpts = nconf.get('redis_client_options');
assert.isDefined(redisOpts, 'redis_client_options not defined in config.json');

var subscriber = redis.createClient(redisOpts);
subscriber.subscribe('observer');

subscriber.on('message', function (channel, message) {
    var worker = new Worker();
    console.log('client got redis message. channel=' + channel + ' message=' + message + ' workerAvailable=' + worker.isAvailable);
    
    // only read the message if worker is available
    if (worker.isAvailable) {

	// only continue if message is saying there's a job
	if (message == 'job') {
            // get job type and details
            worker.getFirstJob(function (err, details) {
		assert.isNull(err, 'error while getting first job');
		assert.isObject(details, 'getting details did not get an object');
		console.log('got first job. deets- ');
		console.log(details);
		
		// execute the job
		worker.execute(details, function(err) {
                    if (err) return console.error('problem executing job- ' + err);
                    console.log('job executed');
		});
	    });
	}
    }
});
