Skip to content

Commit

Permalink
add: profile interval
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpy committed Dec 16, 2020
1 parent 98f23af commit 805697d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
61 changes: 33 additions & 28 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,83 @@
require("dotenv").config();
const convict = require("convict");
require('dotenv').config()
const convict = require('convict')

// Define a schema
const conf = convict({
name: {
format: String,
default: "goodgun",
env: "GUN_NAME",
default: 'goodgun',
env: 'GUN_NAME',
},
peers: {
format: Array,
default: [],
env: "GUN_PEERS",
env: 'GUN_PEERS',
},
gunOpts: {
format: Object,
description: "override or add gun opts",
description: 'override or add gun opts',
default: {},
env: "GUN_OPTS",
env: 'GUN_OPTS',
},
mongoUrl: {
format: String,
default: undefined,
env: "MONGO_URL",
env: 'MONGO_URL',
},
mongoPort: {
format: "port",
default: "27017",
env: "MONGO_PORT",
format: 'port',
default: '27017',
env: 'MONGO_PORT',
},
mongoQuery: {
format: String,
default: "",
env: "MONGO_QUERY",
default: '',
env: 'MONGO_QUERY',
},
mongoDB: {
format: String,
default: "test",
env: "MONGO_DB",
default: 'test',
env: 'MONGO_DB',
},
mongoCollection: {
format: String,
default: "gun_mongo_key",
env: "MONGO_COLLECTION",
default: 'gun_mongo_key',
env: 'MONGO_COLLECTION',
},
serveGun: {
format: Boolean,
default: false,
env: "SERVE_GUN",
env: 'SERVE_GUN',
},
gunPublicS3: {
key: {
format: "*",
format: '*',
default: undefined,
},
secret: {
format: "*",
format: '*',
default: undefined,
},
bucket: {
format: "*",
format: '*',
default: undefined,
},
},
});
heapProfileInterval: {
format: Number,
default: 1000 * 30,
env: 'HEAP_PROFILE_INTERVAL',
},
})

const publicS3 = process.env.GUN_PUBLIC_S3;
const publicS3 = process.env.GUN_PUBLIC_S3
if (publicS3) {
let s3Vals = publicS3.split(",");
let s3Conf = { key: s3Vals[0], secret: s3Vals[1], bucket: s3Vals[2] };
conf.set("gunPublicS3", s3Conf);
let s3Vals = publicS3.split(',')
let s3Conf = { key: s3Vals[0], secret: s3Vals[1], bucket: s3Vals[2] }
conf.set('gunPublicS3', s3Conf)
}
// Perform validation
conf.validate({ allowed: "strict" });
conf.validate({ allowed: 'strict' })
// eslint-disable-next-line

module.exports = conf.getProperties();
module.exports = conf.getProperties()
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ require('@gooddollar/gun/nts')
process.exit(-1)
})

const Config = require('./config.js')

const heapProfile = require('heap-profile')

heapProfile.start()
Expand All @@ -18,10 +20,9 @@ require('@gooddollar/gun/nts')
heapProfile.write((err, filename) => {
console.log(`heapProfile.write. err: ${err} filename: ${filename}`)
})
}, 10 * 60 * 1000).unref()
}, Config.heapProfileInterval).unref()

// es6-way to run IIFE
const Config = require('./config.js')

const { peers, gunOpts, mongoUrl, mongoPort, mongoQuery, mongoDB, mongoCollection, gunPublicS3, serveGun } = Config
const { OPENSHIFT_NODEJS_PORT, VCAP_APP_PORT, PORT, HTTPS_KEY, HTTPS_CERT } = process.env
Expand Down

0 comments on commit 805697d

Please sign in to comment.