Allow to start multiple push tasks
This commit is contained in:
parent
47e1d5d9e0
commit
c8778ffe70
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "uptimekuma-api",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.6",
|
||||
"description": "",
|
||||
"main": "src/index.js",
|
||||
"types": "src/index.d.ts",
|
||||
|
|
14
src/index.d.ts
vendored
14
src/index.d.ts
vendored
|
@ -1,4 +1,8 @@
|
|||
export default class UptimeKumaApi {
|
||||
/**
|
||||
* Creates a new instance of the UptimeKumaApi class
|
||||
* @param baseURL
|
||||
*/
|
||||
constructor(baseURL: string);
|
||||
|
||||
/**
|
||||
|
@ -8,12 +12,20 @@ export default class UptimeKumaApi {
|
|||
*/
|
||||
startPushing(code: string, interval?: number);
|
||||
|
||||
cancelPushing();
|
||||
/**
|
||||
* Stops pushing heartbeats to the server
|
||||
* @param code The monitor code, if not specified, all monitors will be stopped
|
||||
*/
|
||||
cancelPushing(code?: string);
|
||||
|
||||
on(event: "pushSuccessful", handle: (url: string) => void);
|
||||
on(event: "pushFailed", handle: (url: string, err: Error) => void);
|
||||
on(event: "prePush", handle: (url: string, params: {status:"up"|"down",msg:string,ping?:number}) => void);
|
||||
|
||||
/**
|
||||
* Gets the status of public monitors
|
||||
* @param name The name of target status page
|
||||
*/
|
||||
status(name?:string): Promise<[{
|
||||
id: number,
|
||||
name: string,
|
||||
|
|
22
src/index.js
22
src/index.js
|
@ -3,7 +3,7 @@ const EventEmitter = require("events");
|
|||
|
||||
module.exports = class UptimeKumaApi extends EventEmitter {
|
||||
|
||||
_pushTimer;
|
||||
_pushTimers = {};
|
||||
_baseURL;
|
||||
|
||||
constructor(baseURL = "") {
|
||||
|
@ -22,17 +22,25 @@ module.exports = class UptimeKumaApi extends EventEmitter {
|
|||
}
|
||||
|
||||
startPushing(code, interval = 60) {
|
||||
if (this._pushTimer)
|
||||
this._pushTimer.cancel();
|
||||
this._pushTimer = setInterval(() => {
|
||||
if (this._pushTimers[code])
|
||||
this._pushTimers[code].cancel();
|
||||
this._pushTimers[code] = setInterval(() => {
|
||||
this.push(this._baseURL+"api/push/"+code);
|
||||
}, interval * 1000);
|
||||
this.push(this._baseURL+"api/push/"+code);
|
||||
}
|
||||
|
||||
cancelPushing() {
|
||||
if (this._pushTimer)
|
||||
this._pushTimer.cancel();
|
||||
cancelPushing(code = undefined) {
|
||||
if(code) {
|
||||
if (this._pushTimers[code])
|
||||
this._pushTimers[code].cancel();
|
||||
} else {
|
||||
for (let code in this._pushTimers) {
|
||||
if (this._pushTimers.hasOwnProperty(code)) {
|
||||
this._pushTimers[code].cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async status(name = "default") {
|
||||
|
|
Loading…
Reference in a new issue