<commit_before>'use strict';

/**
 * @file Starts the whole updating process to provide updated data for the api
 */

const config = require('../../config');
const dbmanager = require('./dbmanager');
const moment = require('moment');
const logger = require('../logger');

const redis = require('redis');
const redisClient = redis.createClient();

// updater delegates
const saleUpdater = require('./salesUpdater');
const infoUpdater = require('./infoUpdater');

let wasUpdated = true;

logger.info('hexsales-updater started');
logger.info('started inserting new sales');

saleUpdater.update()
  .then(function(_wasUpdated) {
    wasUpdated = _wasUpdated;
    logger.info('finished inserting new sales');
    logger.info('started updating sales data');
    return infoUpdater.update();
  })
  .then(function() {
    logger.info('finished updating sales data');
    if(!wasUpdated) {
      return;
    }
    logger.info('started refreshing views');
    return dbmanager.refreshViews();
  })
  .then(function() {
    logger.info('finished refreshing views');
    redisClient.flushdb();
    logger.info('flushed redis');
    process.exit(0);
  })
  .catch(function(error) {
    logger.error(error);
    process.exit(-1);
  });<commit_msg>flushdb -> flushall in updater<commit_after>'use strict';

/**
 * @file Starts the whole updating process to provide updated data for the api
 */

const config = require('../../config');
const dbmanager = require('./dbmanager');
const moment = require('moment');
const logger = require('../logger');

const redis = require('redis');
const redisClient = redis.createClient();

// updater delegates
const saleUpdater = require('./salesUpdater');
const infoUpdater = require('./infoUpdater');

let wasUpdated = true;

logger.info('hexsales-updater started');
logger.info('started inserting new sales');

saleUpdater.update()
  .then(function(_wasUpdated) {
    wasUpdated = _wasUpdated;
    logger.info('finished inserting new sales');
    logger.info('started updating sales data');
    return infoUpdater.update();
  })
  .then(function() {
    logger.info('finished updating sales data');
    if(!wasUpdated) {
      return;
    }
    logger.info('started refreshing views');
    return dbmanager.refreshViews();
  })
  .then(function() {
    logger.info('finished refreshing views');
    redisClient.flushall();
    logger.info('flushed redis');
    process.exit(0);
  })
  .catch(function(error) {
    logger.error(error);
    process.exit(-1);
  });
{'fraction_non_alphanumeric': 0.15607401448109412, 'fraction_numerical': 0.0016090104585679806, 'mean_word_length': 4.075510204081633, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '3668998', 'n_tokens_mistral': 730, 'n_tokens_neox': 723, 'n_words': 177}