Skip to content

Commit a58d2ff

Browse files
committed
check for both config.env and config.environment when setting api env
1 parent 901e6f4 commit a58d2ff

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

lib/cronitor.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function Cronitor(apiKey, config = {}) {
1717
const path = config.config || process.env.CRONITOR_CONFIG;
1818
const version = config.apiVersion || process.env.CRONITOR_API_VERSION || null;
1919
const timeout = config.timeout || process.env.CRONITOR_TIMEOUT || 10000;
20-
const env = config.env || process.env.CRONITOR_ENV || null;
20+
const env = config.environment || config.env || process.env.CRONITOR_ENVIRONMENT || process.env.CRONITOR_ENV || null;
2121
const headers = {
2222
'User-Agent': 'cronitor-js',
2323
'Authorization': 'Basic ' + new Buffer.from(apiKey + ':').toString('base64'),
@@ -45,7 +45,7 @@ function Cronitor(apiKey, config = {}) {
4545
this.Monitor._api = this._api;
4646
this.Event._api = this._api;
4747

48-
this.generateConfig = async ({path=this.path, group=null}={}) => {
48+
this.generateConfig = async ({ path = this.path, group = null } = {}) => {
4949
let url = 'https://cronitor.io/api/monitors.yaml';
5050

5151
if (!path) {
@@ -66,18 +66,18 @@ function Cronitor(apiKey, config = {}) {
6666
};
6767

6868

69-
this.applyConfig = async function({ path = this.path, rollback = false } = {}) {
69+
this.applyConfig = async function ({ path = this.path, rollback = false } = {}) {
7070
if (!path) throw new Errors.ConfigError('Must include a path to config file e.g. cronitor.applyConfig({path: \'./cronitor.yaml\'})');
7171

7272
try {
73-
config = await this.readConfig({ path, output: true});
73+
config = await this.readConfig({ path, output: true });
7474
} catch (err) {
7575
console.error('Error reading config:', err);
7676
return false
7777
}
7878

7979
try {
80-
await Monitor.put(config, {rollback, format: Monitor.requestType.YAML});
80+
await Monitor.put(config, { rollback, format: Monitor.requestType.YAML });
8181
console.log(`Cronitor config ${rollback ? 'validated' : 'applied'} successfully.`)
8282
return true
8383
} catch (err) {
@@ -86,11 +86,11 @@ function Cronitor(apiKey, config = {}) {
8686
}
8787
};
8888

89-
this.validateConfig = async ({ path = this.path} = {}) => {
89+
this.validateConfig = async ({ path = this.path } = {}) => {
9090
return this.applyConfig({ path, rollback: true });
9191
};
9292

93-
this.readConfig = async function({path = null, output = false}={}) {
93+
this.readConfig = async function ({ path = null, output = false } = {}) {
9494
if (!path) throw new Errors.ConfigError('Must include a path to config file e.g. cronitor.readConfig({path: \'./cronitor.yaml\'})');
9595
if (!this.path) this.path = path;
9696

@@ -106,9 +106,9 @@ function Cronitor(apiKey, config = {}) {
106106
};
107107

108108

109-
this.wrap = function(key, callback) {
109+
this.wrap = function (key, callback) {
110110
const _cronitor = this;
111-
return async function(args) {
111+
return async function (args) {
112112
const monitor = new _cronitor.Monitor(key);
113113
const series = _cronitor.newSeries();
114114
await monitor.ping({ state: _cronitor.Monitor.State.RUN, series });
@@ -123,20 +123,20 @@ function Cronitor(apiKey, config = {}) {
123123
};
124124
};
125125

126-
this.wraps = function(lib) {
126+
this.wraps = function (lib) {
127127
// https://github.com/node-cron/node-cron
128128
if (lib.schedule) {
129-
this.schedule = function(key, schedule, cb, options) {
129+
this.schedule = function (key, schedule, cb, options) {
130130
const job = this.wrap(key, cb);
131131
return lib.schedule(schedule, job, options);
132132
};
133133
} else if (lib.job) { // https://github.com/kelektiv/node-cron
134-
this.job = function(key, schedule, cb) {
134+
this.job = function (key, schedule, cb) {
135135
const wrapped = this.wrap(key, cb);
136136
return lib.job(schedule, wrapped);
137137
};
138138

139-
this.schedule = function(key, schedule, cb) {
139+
this.schedule = function (key, schedule, cb) {
140140
const job = this.job(key, schedule, cb);
141141
job.start();
142142
};

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cronitor",
3-
"version": "2.4.0",
3+
"version": "2.4.1",
44
"description": "A simple library for reliably monitoring cron jobs, control-loops, or other important system events with Cronitor.",
55
"main": "lib/cronitor.js",
66
"repository": {
@@ -38,4 +38,4 @@
3838
"sinon-chai": "^3.7.0",
3939
"sinon-stub-promise": "^4.0.0"
4040
}
41-
}
41+
}

0 commit comments

Comments
 (0)