Last active
May 4, 2017 01:19
-
-
Save morphatic/e346797f745a375f230b155e59cdd20f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Instructions | |
* | |
* 1. mkdir deploymonitor | |
* 2. cd deploymonitor | |
* 3. npm init | |
* 4. accept all defaults is fine | |
* 5. npm install @akanass/rx-http-request | |
* 6. paste code below into new file index.js | |
* 7. update username, password, other variables | |
* 8. node index | |
*/ | |
// import necessary libraries | |
const Rx = require('rxjs/Rx'); | |
const RxHR = require('@akanass/rx-http-request').RxHR; | |
let auth = { | |
body: { | |
username: 'cpt_hcus', | |
password: 'PASSWORD' | |
}, | |
json: true | |
}; | |
// first authenticate | |
RxHR.post('https://anypoint.mulesoft.com/accounts/login', auth).subscribe(auth_res => { | |
// once authenticated | |
// set up API request | |
let auth = JSON.parse(auth_res.response.body); | |
let app = 'hcus-dv-v1-helloworld'; | |
let uri = 'https://anypoint.mulesoft.com/cloudhub/api/v2/applications/' + app; | |
let opts = { | |
json: true, | |
header: { | |
'Authorization': `${auth.token_type} ${auth.access_token}`, | |
'X-ANYPNT-ENV-ID' : '98d9fc05-f806-4818-a242-236b4f1ffc16' | |
} | |
}; | |
// create our polling source | |
let source = Rx.Observable.interval(1000).flatMap(() => RxHR.get(uri, opts)); | |
// start polling | |
let subscription = source.subscribe( | |
res => { | |
// here you check to see if deploy finished | |
// assuming you have some sort of way to know that... | |
if(res.response.statusCode === 200) { | |
console.log('Successful deploy'); | |
subscription.unsubscribe(); // stop polling | |
} else { | |
console.log('Not deployed yet...'); | |
} | |
}, | |
err => { | |
console.log('Error: ', err); | |
} | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment