An example of utilizing the rxjs-probe library.
npm run subscribe
import { Probe } from '@rxjs-probe/core';
import { HttpProbePerformer } from '@rxjs-probe/http-probe-performer';
const probe = new Probe({
performer: new HttpProbePerformer({
host: 'github.com',
path: '/a179346/rxjs-probe',
scheme: 'HTTPS',
}),
initialDelaySeconds: 1,
periodSeconds: 1,
timeoutSeconds: 1,
successThreshold: 1,
failureThreshold: 1,
});
probe.createObservable().subscribe(status => {
console.log('status:', status);
});
// Expected output:
// 0s -> status: unknown
// 1s -> status: healthy
npm run wait-for-healthy
import { firstValueFrom, filter } from 'rxjs';
import { Probe } from '@rxjs-probe/core';
import { HttpProbePerformer } from '@rxjs-probe/http-probe-performer';
main();
async function main() {
const probe = new Probe({
performer: new HttpProbePerformer({
host: 'github.com',
path: '/a179346/rxjs-probe',
scheme: 'HTTPS',
}),
initialDelaySeconds: 3,
});
console.log('Waiting for healthy status...');
await firstValueFrom(probe.createObservable().pipe(filter(status => status === 'healthy')));
console.log('Healthy!');
}
// Expected output:
// 0s -> Waiting for healthy status...
// 3s -> Healthy!
npm run custom-probe-performer
import { Probe, ProbePerformer } from '@rxjs-probe/core';
import axios from 'axios';
const customProbePerformer = new ProbePerformer(async timeoutSeconds => {
console.log('Performing probe...');
await axios({
url: 'https://github.com/a179346/rxjs-probe',
timeout: timeoutSeconds * 1000,
validateStatus: status => status === 200,
});
});
const probe = new Probe({
performer: customProbePerformer,
});
probe.createObservable().subscribe(status => {
console.log('status:', status);
});
// Expected output:
// 0s -> status: unknown
// 0s -> Performing probe...
// 0s -> status: healthy
// 10s -> Performing probe...
// 20s -> Performing probe...
// 30s -> Performing probe...
// ....