diff --git a/index.js b/index.js index 35cdf4f..d920b5a 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ const { ClusterManager } = require('detritus-client'); +const { basecamp } = require('./labscore/logging'); const time = Date.now(); @@ -17,6 +18,15 @@ const manager = new ClusterManager(client, token, { (async () => { console.log(`v2 | starting v2.`) + manager.on("clusterProcess", ({ clusterProcess }) => { + clusterProcess.on('close', ({code, signal}) => { + basecamp(`<:ico_w4:1086624964284788787>\`[${process.env.HOSTNAME}]\` **\` CLUSTER_CLOSED \`** Cluster ${clusterProcess.clusterId} closed with code \`${code}\` and signal \`${signal}\` @ \`${Date.now()}\``) + }); + clusterProcess.on('warn', async ({error}) => { + await basecamp(`<:ico_w2:1086624961025810485>\`[${process.env.HOSTNAME}]\` **\` CLUSTER_WARNING \`** Cluster ${clusterProcess.clusterId} issued warning @ \`${Date.now()}\``) + await basecamp(`\`\`\`js\n${error}\`\`\``) + }); + }) await manager.run(); console.log(`v2 | ready. took ${(Date.now() - time) / 1000}.`) })(); \ No newline at end of file diff --git a/labscore/logging.js b/labscore/logging.js index b4b9102..b0e92f8 100644 --- a/labscore/logging.js +++ b/labscore/logging.js @@ -23,4 +23,19 @@ module.exports.maintower = async function (packages, type){ console.log(e) throw "Maintower request failed." } +} + +module.exports.basecamp = async function (log){ + try{ + let res = await superagent.post(MAINTOWER_BASE_URL + 'basecamp') + .set({ + "Authorization": process.env.api_prod, + "x-labscore-client": "labscore/2.0" + }) + .send({log}) + return; + }catch(e){ + console.log(e) + throw "Basecamp request failed." + } } \ No newline at end of file