<commit_before>/**
 * System controller for functions such as /about and /monitor
 */
 const canvasApi = require('../canvasApi')
 const rp = require('request-promise')
 const express = require('express')
 const router = express.Router()
 const config = require('./init/configuration')
 const version = require('../config/version')
 const packageFile = require('../package.json')
 const moment = require('moment')
 const consumeMessages = require('../messages/consumeMessages')
 const [waitAmount, waitUnit] = [10, 'hours'] 
 let idleTimeStart = moment()
 
/* GET /_about
 * About page
 */
 var _about = function (req, res) {
   res.setHeader('Content-Type', 'text/plain')
   res.send(`
    packageFile.name:${packageFile.name}
    packageFile.version:${packageFile.version}
    packageFile.description:${packageFile.description}
    version.gitBranch:${version.gitBranch}
    version.gitCommit:${version.gitCommit}
    version.jenkinsBuild:${version.jenkinsBuild}
    version.dockerName:${version.dockerName}
    version.dockerVersion:${version.dockerVersion}
    version.jenkinsBuildDate:${version.jenkinsBuildDate}`)
 }

 consumeMessages.eventEmitter.on('processMessageStart', () => {
   idleTimeStart = moment()
 })

 function status () {
   const checkCanvasStatus = rp('http://nlxv32btr6v7.statuspage.io/api/v2/status.json')
    .then(JSON.parse)
    .then(data => data.status.indicator === 'none')
   let readAccountInCanvas = canvasApi.getRootAccount()
   let canvasOk, canvasKeyOk

   return checkCanvasStatus
   .then(_canvasOk => { canvasOk = _canvasOk })
   .catch(e => { canvasOk = false })
   .then(() => readAccountInCanvas)
   .then(keyOk => { canvasKeyOk = keyOk })
   .catch(e => { canvasKeyOk = false })
   .then(() => {
     return {canvasOk, canvasKeyOk}
   })
 }

 var _monitor = function (req, res) {
   status().then(({canvasOk, canvasKeyOk}) => {
     res.setHeader('Content-Type', 'text/plain')
     
     let idleTimeOk = idleTimeStart.isAfter(moment().subtract(waitAmount, waitUnit))
     
     res.send(`APPLICATION_STATUS: ${idleTimeOk && canvasKeyOk && canvasOk ? 'OK' : 'ERROR'} ${packageFile.name}-${packageFile.version}-${version.jenkinsBuild}
READ MESSAGE FROM AZURE: ${idleTimeOk ? `OK. The server has waited less then ${waitAmount} ${waitUnit} for a message.` : `ERROR. The server has not received a message in the last ${waitAmount} ${waitUnit}`}
CANVAS: ${canvasOk ? 'OK' : 'Canvas is down'}
CANVASKEY: ${canvasKeyOk ? 'OK' : 'Invalid access token (in case if CANVAS is "OK")'}
  `)
   })
 }

 router.get('/_monitor', _monitor)
 router.get('/_monitor_all', _monitor)

 router.get('/_monitor_core', _monitor)
 router.get('/_about', _about)

 router.get('/', function (req, res) {
   res.redirect(`${config.full.proxyPrefixPath.uri}/_monitor`)
 })

 module.exports = router<commit_msg>removed one more const<commit_after>/**
 * System controller for functions such as /about and /monitor
 */
 const canvasApi = require('../canvasApi')
 const rp = require('request-promise')
 const express = require('express')
 const router = express.Router()
 const config = require('./init/configuration')
 const version = require('../config/version')
 const packageFile = require('../package.json')
 const moment = require('moment')
 const consumeMessages = require('../messages/consumeMessages')
 const [waitAmount, waitUnit] = [10, 'hours']
 let idleTimeStart = moment()

/* GET /_about
 * About page
 */
 var _about = function (req, res) {
   res.setHeader('Content-Type', 'text/plain')
   res.send(`
    packageFile.name:${packageFile.name}
    packageFile.version:${packageFile.version}
    packageFile.description:${packageFile.description}
    version.gitBranch:${version.gitBranch}
    version.gitCommit:${version.gitCommit}
    version.jenkinsBuild:${version.jenkinsBuild}
    version.dockerName:${version.dockerName}
    version.dockerVersion:${version.dockerVersion}
    version.jenkinsBuildDate:${version.jenkinsBuildDate}`)
 }

 consumeMessages.eventEmitter.on('processMessageStart', () => {
   idleTimeStart = moment()
 })

 function status () {
   let checkCanvasStatus = rp('http://nlxv32btr6v7.statuspage.io/api/v2/status.json')
    .then(JSON.parse)
    .then(data => data.status.indicator === 'none')
   let readAccountInCanvas = canvasApi.getRootAccount()
   let canvasOk, canvasKeyOk

   return checkCanvasStatus
   .then(_canvasOk => { canvasOk = _canvasOk })
   .catch(e => { canvasOk = false })
   .then(() => readAccountInCanvas)
   .then(keyOk => { canvasKeyOk = keyOk })
   .catch(e => { canvasKeyOk = false })
   .then(() => {
     return {canvasOk, canvasKeyOk}
   })
 }

 var _monitor = function (req, res) {
   status().then(({canvasOk, canvasKeyOk}) => {
     res.setHeader('Content-Type', 'text/plain')

     let idleTimeOk = idleTimeStart.isAfter(moment().subtract(waitAmount, waitUnit))

     res.send(`APPLICATION_STATUS: ${idleTimeOk && canvasKeyOk && canvasOk ? 'OK' : 'ERROR'} ${packageFile.name}-${packageFile.version}-${version.jenkinsBuild}
READ MESSAGE FROM AZURE: ${idleTimeOk ? `OK. The server has waited less then ${waitAmount} ${waitUnit} for a message.` : `ERROR. The server has not received a message in the last ${waitAmount} ${waitUnit}`}
CANVAS: ${canvasOk ? 'OK' : 'Canvas is down'}
CANVASKEY: ${canvasKeyOk ? 'OK' : 'Invalid access token (in case if CANVAS is "OK")'}
  `)
   })
 }

 router.get('/_monitor', _monitor)
 router.get('/_monitor_all', _monitor)

 router.get('/_monitor_core', _monitor)
 router.get('/_about', _about)

 router.get('/', function (req, res) {
   res.redirect(`${config.full.proxyPrefixPath.uri}/_monitor`)
 })

 module.exports = router
{'fraction_non_alphanumeric': 0.15930459464254035, 'fraction_numerical': 0.002483590562355863, 'mean_word_length': 4.359315589353612, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '884038', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1734, 'n_words': 376}