<commit_before>exports.init = function init(app) {

  var redis = require("redis"), redisClient;
  if (process.env.VCAP_SERVICES) {
    var serviceCredentials = JSON.parse(process.env.VCAP_SERVICES)["rediscloud-n/a"][0].credentials;
    redisClient = redis.createClient(serviceCredentials.port, serviceCredentials.hostname);
    redisClient.auth(serviceCredentials.password);
  } else {
    redisClient = redis.createClient();
  }

  app.post('/matches', function(req, res){
    console.log(req.body);

    function guid() {
      return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(char) {
        var rand = Math.random()*16|0, charReplacement = (char == 'x') ? rand : (rand&0x3|0x8);

        return charReplacement.toString(16);
      });
    }

    var requestGuid = guid();
    setTimeout(function() { scheduleMatch(req.body, requestGuid) }, 0);
    saveMatch(requestGuid, req.body, function() { res.send({guid: requestGuid}) });
  });

  app.get('/matches/:guid', function(req, res){
    console.log('polling received for: ' + req.params.guid);
    redisClient.hgetall(req.params.guid, function(err, savedMatch){
      if(!savedMatch) {
        res.status(404).send({});
        return;
      }

      if(savedMatch.opponentNames) {
        res.send({opponentNames: savedMatch.opponentNames});
      } else {
        res.send({});
      }
    });
  });

  var saveMatch = function(guid, matchDetails, callback){
    redisClient.hmset(guid, matchDetails, callback);
  };<commit_msg>Send back status 304 when a match still hasn't been scheduled and placeholder assignedTables<commit_after>exports.init = function init(app) {

  var redis = require("redis"), redisClient;
  if (process.env.VCAP_SERVICES) {
    var serviceCredentials = JSON.parse(process.env.VCAP_SERVICES)["rediscloud-n/a"][0].credentials;
    redisClient = redis.createClient(serviceCredentials.port, serviceCredentials.hostname);
    redisClient.auth(serviceCredentials.password);
  } else {
    redisClient = redis.createClient();
  }

  app.post('/matches', function(req, res){
    console.log(req.body);

    function guid() {
      return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(char) {
        var rand = Math.random()*16|0, charReplacement = (char == 'x') ? rand : (rand&0x3|0x8);

        return charReplacement.toString(16);
      });
    }

    var requestGuid = guid();
    setTimeout(function() { scheduleMatch(req.body, requestGuid) }, 0);
    saveMatch(requestGuid, req.body, function() { res.send({guid: requestGuid}) });
  });

  app.get('/matches/:guid', function(req, res){
    console.log('polling received for: ' + req.params.guid);
    redisClient.hgetall(req.params.guid, function(err, savedMatch){
      if(!savedMatch) {
        res.status(404).send({});
        return;
      }

      if(savedMatch.opponentNames) {
        res.send({opponentNames: savedMatch.opponentNames, assignedTable: "5th floor tables"});
      } else {
        res.status(304).send({});
      }
    });
  });

  var saveMatch = function(guid, matchDetails, callback){
    redisClient.hmset(guid, matchDetails, callback);
  };
{'fraction_non_alphanumeric': 0.15658816040738383, 'fraction_numerical': 0.011775938892425206, 'mean_word_length': 3.588321167883212, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '4356248', 'n_tokens_mistral': 1034, 'n_tokens_neox': 996, 'n_words': 169}