@@ -17,7 +17,7 @@ function Cronitor(apiKey, config = {}) {
17
17
const path = config . config || process . env . CRONITOR_CONFIG ;
18
18
const version = config . apiVersion || process . env . CRONITOR_API_VERSION || null ;
19
19
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 ;
21
21
const headers = {
22
22
'User-Agent' : 'cronitor-js' ,
23
23
'Authorization' : 'Basic ' + new Buffer . from ( apiKey + ':' ) . toString ( 'base64' ) ,
@@ -45,7 +45,7 @@ function Cronitor(apiKey, config = {}) {
45
45
this . Monitor . _api = this . _api ;
46
46
this . Event . _api = this . _api ;
47
47
48
- this . generateConfig = async ( { path= this . path , group= null } = { } ) => {
48
+ this . generateConfig = async ( { path = this . path , group = null } = { } ) => {
49
49
let url = 'https://cronitor.io/api/monitors.yaml' ;
50
50
51
51
if ( ! path ) {
@@ -66,18 +66,18 @@ function Cronitor(apiKey, config = {}) {
66
66
} ;
67
67
68
68
69
- this . applyConfig = async function ( { path = this . path , rollback = false } = { } ) {
69
+ this . applyConfig = async function ( { path = this . path , rollback = false } = { } ) {
70
70
if ( ! path ) throw new Errors . ConfigError ( 'Must include a path to config file e.g. cronitor.applyConfig({path: \'./cronitor.yaml\'})' ) ;
71
71
72
72
try {
73
- config = await this . readConfig ( { path, output : true } ) ;
73
+ config = await this . readConfig ( { path, output : true } ) ;
74
74
} catch ( err ) {
75
75
console . error ( 'Error reading config:' , err ) ;
76
76
return false
77
77
}
78
78
79
79
try {
80
- await Monitor . put ( config , { rollback, format : Monitor . requestType . YAML } ) ;
80
+ await Monitor . put ( config , { rollback, format : Monitor . requestType . YAML } ) ;
81
81
console . log ( `Cronitor config ${ rollback ? 'validated' : 'applied' } successfully.` )
82
82
return true
83
83
} catch ( err ) {
@@ -86,11 +86,11 @@ function Cronitor(apiKey, config = {}) {
86
86
}
87
87
} ;
88
88
89
- this . validateConfig = async ( { path = this . path } = { } ) => {
89
+ this . validateConfig = async ( { path = this . path } = { } ) => {
90
90
return this . applyConfig ( { path, rollback : true } ) ;
91
91
} ;
92
92
93
- this . readConfig = async function ( { path = null , output = false } = { } ) {
93
+ this . readConfig = async function ( { path = null , output = false } = { } ) {
94
94
if ( ! path ) throw new Errors . ConfigError ( 'Must include a path to config file e.g. cronitor.readConfig({path: \'./cronitor.yaml\'})' ) ;
95
95
if ( ! this . path ) this . path = path ;
96
96
@@ -106,9 +106,9 @@ function Cronitor(apiKey, config = {}) {
106
106
} ;
107
107
108
108
109
- this . wrap = function ( key , callback ) {
109
+ this . wrap = function ( key , callback ) {
110
110
const _cronitor = this ;
111
- return async function ( args ) {
111
+ return async function ( args ) {
112
112
const monitor = new _cronitor . Monitor ( key ) ;
113
113
const series = _cronitor . newSeries ( ) ;
114
114
await monitor . ping ( { state : _cronitor . Monitor . State . RUN , series } ) ;
@@ -123,20 +123,20 @@ function Cronitor(apiKey, config = {}) {
123
123
} ;
124
124
} ;
125
125
126
- this . wraps = function ( lib ) {
126
+ this . wraps = function ( lib ) {
127
127
// https://github.com/node-cron/node-cron
128
128
if ( lib . schedule ) {
129
- this . schedule = function ( key , schedule , cb , options ) {
129
+ this . schedule = function ( key , schedule , cb , options ) {
130
130
const job = this . wrap ( key , cb ) ;
131
131
return lib . schedule ( schedule , job , options ) ;
132
132
} ;
133
133
} else if ( lib . job ) { // https://github.com/kelektiv/node-cron
134
- this . job = function ( key , schedule , cb ) {
134
+ this . job = function ( key , schedule , cb ) {
135
135
const wrapped = this . wrap ( key , cb ) ;
136
136
return lib . job ( schedule , wrapped ) ;
137
137
} ;
138
138
139
- this . schedule = function ( key , schedule , cb ) {
139
+ this . schedule = function ( key , schedule , cb ) {
140
140
const job = this . job ( key , schedule , cb ) ;
141
141
job . start ( ) ;
142
142
} ;
0 commit comments