<commit_before>'use strict'

let connection = require('../../db/connection')
let logger = require('tracer').colorConsole()

module.exports.Stage = class Stage {

  /**
   *
   */
  constructor(successCallback, failureCallback, stageConfig) {
    this.successCallback = successCallback
    this.failureCallback = failureCallback
    this.stageConfig = stageConfig
  }

  /**
   * Mark a stage as failed
   */
  fail() {
    this.failureCallback()
  }

  /**
   * Mark a stage as successful
   */
  succeed() {
    this.successCallback()
  }

  /**
   * Get an option that the user configured for this stage instance
   */
  option(key) {
    return this.stageConfig.data[key]
  }

  /**
   * Add a new log
   *
   * @param {string|class|object} log
   */
  log(log) {

    // If a string is passed, format it as an object
    if (typeof log === 'string') {
      log = {
        title: log
      }
    }

    let data = {
      pipeline_execution_id: null, // TODO
      stage_execution_id: null, // TODO
      type: log.type || null,
      title: log.title,
      data: log.data ? JSON.stringify(log.data) : null
    }

    connection.insert(data).into('pipeline_execution_logs').catch((err) => {
      logger.error(err)
    })
  }

}<commit_msg>Fixing option lookup<commit_after>'use strict'

let connection = require('../../db/connection')
let logger = require('tracer').colorConsole()

module.exports.Stage = class Stage {

  /**
   *
   */
  constructor(successCallback, failureCallback, stageConfig) {
    this.successCallback = successCallback
    this.failureCallback = failureCallback
    this.stageConfig = stageConfig
    this.stageConfig.options = JSON.parse(this.stageConfig.options)
  }

  /**
   * Mark a stage as failed
   */
  fail() {
    this.failureCallback()
  }

  /**
   * Mark a stage as successful
   */
  succeed() {
    this.successCallback()
  }

  /**
   * Get an option that the user configured for this stage instance
   */
  option(key) {
    return this.stageConfig.options[key]
  }

  /**
   * Add a new log
   *
   * @param {string|class|object} log
   */
  log(log) {

    // If a string is passed, format it as an object
    if (typeof log === 'string') {
      log = {
        title: log
      }
    }

    let data = {
      pipeline_execution_id: null, // TODO
      stage_execution_id: null, // TODO
      type: log.type || null,
      title: log.title,
      data: log.data ? JSON.stringify(log.data) : null
    }

    connection.insert(data).into('pipeline_execution_logs').catch((err) => {
      logger.error(err)
    })
  }

}
{'fraction_non_alphanumeric': 0.133852140077821, 'fraction_numerical': 0.0, 'mean_word_length': 2.396301188903567, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3800522', 'n_tokens_mistral': 814, 'n_tokens_neox': 796, 'n_words': 188}