<commit_before>Q = require 'q'
DataStore = require './datastore/datastore'
Operations = require './operations'

logger = require('../lib/logger')

module.exports = class ProcessingChainEntrance
  constructor: (@engine, @journal, @replication) ->

  start: =>
    #logger.info("Starting PCE")
    Q.all [
      @journal.start(@forward_operation).then =>
        console.log 'INITIALIZED/REPLAYED LOG'
      @replication.start() ]

  forward_operation: (operation) =>
    message = JSON.stringify(operation)
    Q.all([
      @journal.record(message)
      @replication.send(message)
    ]).then(=> @package_operation(operation))

  package_operation: (operation) =>
    deferred = Q.defer()
    try
      deferred.resolve @engine.execute_operation(operation)
    catch err
      deferred.reject(err)

    return deferred.promise<commit_msg>Simplyfiy Q integration with trade engine<commit_after>Q = require 'q'
DataStore = require './datastore/datastore'
Operations = require './operations'

logger = require('../lib/logger')

module.exports = class ProcessingChainEntrance
  constructor: (@engine, @journal, @replication) ->

  start: =>
    #logger.info("Starting PCE")
    Q.all [
      @journal.start(@forward_operation).then =>
        console.log 'INITIALIZED/REPLAYED LOG'
      @replication.start() ]

  forward_operation: (operation) =>
    message = JSON.stringify(operation)
    Q.all([
      @journal.record(message)
      @replication.send(message)
    ]).then(=> @package_operation(operation))

  package_operation: (operation) =>
    Q.fcall @engine.execute_operation(operation)

{'fraction_non_alphanumeric': 0.13810420590081607, 'fraction_numerical': 0.0, 'mean_word_length': 3.744047619047619, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1989379', 'n_tokens_mistral': 488, 'n_tokens_neox': 475, 'n_words': 92}