@ancon/wildcat-utils 1.34.1 → 1.34.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hangfire/createHangfirePoller.d.ts +2 -1
- package/hangfire/createHangfirePoller.js +1 -1
- package/hangfire/createHangfirePoller.mjs +20 -15
- package/hangfire/createMakeHangfireRequest.d.ts +2 -2
- package/hangfire/createMakeHangfireRequest.js +1 -1
- package/hangfire/createMakeHangfireRequest.mjs +13 -12
- package/package.json +1 -1
|
@@ -30,9 +30,10 @@ declare class HangfirePoller {
|
|
|
30
30
|
private startTimer;
|
|
31
31
|
private executeWorkerRequest;
|
|
32
32
|
private deleteWorker;
|
|
33
|
-
createWorker(groupId: string, { workerId, url, }: {
|
|
33
|
+
createWorker(groupId: string, { workerId, url, headers, }: {
|
|
34
34
|
workerId: string;
|
|
35
35
|
url: string;
|
|
36
|
+
headers: APIHeaders;
|
|
36
37
|
}): Promise<unknown>;
|
|
37
38
|
triggerWorker(workerId: string): void;
|
|
38
39
|
/** May be called either before or after `createWorker()` */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var f=Object.defineProperty;var p=(t,e,r)=>e in t?f(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var i=(t,e,r)=>(p(t,typeof e!="symbol"?e+"":e,r),r);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const b=require("axios"),n=require("@ancon/wildcat-types"),a=require("../error/createCodedError.js"),m=require("../api/isNoContentResponse.js");class c{constructor(e){i(this,"busyWorkers",new Set);i(this,"enabledGroups",new Set);i(this,"groups",new Map);i(this,"workerByIdMap",new Map);i(this,"timer",null);i(this,"config",{maxGroupsSize:50,maxWorkersSize:20,getIsNetworkOnline(){return!0},async getRequestHeaders(){return{}},debug(...e){console.log(...e)}});this.config={...this.config,...e??null}}stopTimer(){this.timer!=null&&(this.config.debug("*stop timer*"),clearInterval(this.timer),this.timer=null)}startTimer(){if(this.timer!=null)throw a(new Error("Timer already started"),n.ErrorCode.GenericUnexpectedHangfireError);this.config.debug("*start timer*"),this.timer=setInterval(()=>{this.config.debug("*tick*",{busyWorkers:this.busyWorkers.size,enabledGroups:this.enabledGroups.size,groups:this.groups}),this.enabledGroups.forEach(e=>{const r=this.groups.get(e);r&&r.forEach(s=>this.executeWorkerRequest(s))}),this.groups.size<1&&this.stopTimer()},5e3)}async executeWorkerRequest(e){const r=this.config.getIsNetworkOnline();!this.busyWorkers.has(e.workerId)&&r&&(this.busyWorkers.add(e.workerId),b({url:e.url,method:"get",headers:{...await this.config.getRequestHeaders(),...e.headers}}).then(s=>{s&&!m(s)?(e.resolve(s),this.deleteWorker(e.groupId,e.workerId)):this.busyWorkers.delete(e.workerId)}).catch(s=>{e.reject(s),this.deleteWorker(e.groupId,e.workerId)}))}deleteWorker(e,r){const s=this.groups.get(e);s&&(this.config.debug("*delete worker*",s.size,s),s.delete(r),this.workerByIdMap.delete(r),this.busyWorkers.delete(r),s.size<1&&(this.groups.delete(e),this.enabledGroups.delete(e),this.enabledGroups.size<1&&this.stopTimer()))}createWorker(e,{workerId:r,url:s,headers:g}){if(!this.groups.has(e)){if(this.groups.size>=this.config.maxGroupsSize){const u=a(new Error("Max number of Hangfire groups exceeded"),n.ErrorCode.GenericUnexpectedHangfireError,{count:this.groups.size});throw this.destroy(),u}this.groups.set(e,new Map)}const o=this.groups.get(e);return new Promise((u,h)=>{if(o.has(r))throw a(new Error("Duplicate Hangfire worker ID"),n.ErrorCode.GenericUnexpectedHangfireError);if(o.size>=this.config.maxWorkersSize){const d=a(new Error("Max number of Hangfire workers in group exceeded"),n.ErrorCode.GenericUnexpectedHangfireError,{groupId:e,count:o.size});throw h(d),this.destroy(),d}const l={workerId:r,groupId:e,url:s,resolve:u,reject:h,headers:g};o.set(r,l),this.workerByIdMap.set(r,l),this.enabledGroups.has(e)||this.enabledGroups.add(e),this.timer==null&&this.enabledGroups.size>0&&this.startTimer()})}triggerWorker(e){this.config.debug("*triggerWorker*");const r=this.workerByIdMap.get(e);r&&this.executeWorkerRequest(r)}enableWorkers(e){this.config.debug("*enable*",e),this.enabledGroups.add(e),this.groups.has(e)&&this.timer==null&&this.startTimer()}disableWorkers(e){this.config.debug("*disable*",e),this.enabledGroups.delete(e),this.enabledGroups.size<1&&this.stopTimer()}destroy(){this.config.debug("*destroy*"),this.groups.clear(),this.stopTimer()}}function k(t){return new c(t)}exports.HangfirePoller=c;exports.default=k;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var i = (t, e, r) => (
|
|
4
|
-
import
|
|
1
|
+
var c = Object.defineProperty;
|
|
2
|
+
var f = (t, e, r) => e in t ? c(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
|
+
var i = (t, e, r) => (f(t, typeof e != "symbol" ? e + "" : e, r), r);
|
|
4
|
+
import p from "axios";
|
|
5
5
|
import { ErrorCode as n } from "@ancon/wildcat-types";
|
|
6
6
|
import h from "../error/createCodedError.mjs";
|
|
7
|
-
import
|
|
8
|
-
class
|
|
7
|
+
import m from "../api/isNoContentResponse.mjs";
|
|
8
|
+
class b {
|
|
9
9
|
constructor(e) {
|
|
10
10
|
/** Workers currently executing a request */
|
|
11
11
|
i(this, "busyWorkers", /* @__PURE__ */ new Set());
|
|
@@ -56,12 +56,15 @@ class m {
|
|
|
56
56
|
}
|
|
57
57
|
async executeWorkerRequest(e) {
|
|
58
58
|
const r = this.config.getIsNetworkOnline();
|
|
59
|
-
!this.busyWorkers.has(e.workerId) && r && (this.busyWorkers.add(e.workerId),
|
|
59
|
+
!this.busyWorkers.has(e.workerId) && r && (this.busyWorkers.add(e.workerId), p({
|
|
60
60
|
url: e.url,
|
|
61
61
|
method: "get",
|
|
62
|
-
headers:
|
|
62
|
+
headers: {
|
|
63
|
+
...await this.config.getRequestHeaders(),
|
|
64
|
+
...e.headers
|
|
65
|
+
}
|
|
63
66
|
}).then((s) => {
|
|
64
|
-
s && !
|
|
67
|
+
s && !m(s) ? (e.resolve(s), this.deleteWorker(e.groupId, e.workerId)) : this.busyWorkers.delete(e.workerId);
|
|
65
68
|
}).catch((s) => {
|
|
66
69
|
e.reject(s), this.deleteWorker(e.groupId, e.workerId);
|
|
67
70
|
}));
|
|
@@ -72,7 +75,8 @@ class m {
|
|
|
72
75
|
}
|
|
73
76
|
createWorker(e, {
|
|
74
77
|
workerId: r,
|
|
75
|
-
url: s
|
|
78
|
+
url: s,
|
|
79
|
+
headers: g
|
|
76
80
|
}) {
|
|
77
81
|
if (!this.groups.has(e)) {
|
|
78
82
|
if (this.groups.size >= this.config.maxGroupsSize) {
|
|
@@ -105,7 +109,8 @@ class m {
|
|
|
105
109
|
groupId: e,
|
|
106
110
|
url: s,
|
|
107
111
|
resolve: a,
|
|
108
|
-
reject: u
|
|
112
|
+
reject: u,
|
|
113
|
+
headers: g
|
|
109
114
|
};
|
|
110
115
|
o.set(r, l), this.workerByIdMap.set(r, l), this.enabledGroups.has(e) || this.enabledGroups.add(e), this.timer == null && this.enabledGroups.size > 0 && this.startTimer();
|
|
111
116
|
});
|
|
@@ -126,10 +131,10 @@ class m {
|
|
|
126
131
|
this.config.debug("*destroy*"), this.groups.clear(), this.stopTimer();
|
|
127
132
|
}
|
|
128
133
|
}
|
|
129
|
-
function
|
|
130
|
-
return new
|
|
134
|
+
function x(t) {
|
|
135
|
+
return new b(t);
|
|
131
136
|
}
|
|
132
137
|
export {
|
|
133
|
-
|
|
134
|
-
|
|
138
|
+
b as HangfirePoller,
|
|
139
|
+
x as default
|
|
135
140
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { APIParams, APIPostRequest, APIPutRequest } from '@ancon/wildcat-types';
|
|
1
|
+
import type { APIHeaders, APIParams, APIPostRequest, APIPutRequest } from '@ancon/wildcat-types';
|
|
2
2
|
import type { AxiosResponse } from 'axios';
|
|
3
3
|
import { HangfirePoller } from './createHangfirePoller';
|
|
4
4
|
/**
|
|
@@ -6,5 +6,5 @@ import { HangfirePoller } from './createHangfirePoller';
|
|
|
6
6
|
* @param hangfirePoller `HangfirePoller` instance from `createHangfirePoller()`
|
|
7
7
|
* @returns `makeHangfireRequest()` callback function
|
|
8
8
|
*/
|
|
9
|
-
declare function createMakeHangfireRequest(hangfirePoller: HangfirePoller): <TData extends Record<string, any>, TParams extends APIParams>(request: APIPostRequest<unknown, TData, TParams> | APIPutRequest<unknown, TData, TParams>, data: TData, params: TParams, groupId: string) => Promise<AxiosResponse>;
|
|
9
|
+
declare function createMakeHangfireRequest(hangfirePoller: HangfirePoller): <TData extends Record<string, any>, TParams extends APIParams>(request: APIPostRequest<unknown, TData, TParams> | APIPutRequest<unknown, TData, TParams>, data: TData, params: TParams, groupId: string, headers?: APIHeaders) => Promise<AxiosResponse>;
|
|
10
10
|
export default createMakeHangfireRequest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const c=require("./isHangfireResponse.js");require("../api/isAcceptedResponse.js");function f(e,t){return`${e.config.baseURL??""}/${e.config.url??""}/status/${t}`}function g(e){return async function(u,a,s,o,n={}){const r=await u(a,s,n);if(c(r)){const i=r.data.id;return e.createWorker(o,{workerId:i,url:f(r,i),headers:n})}return r}}module.exports=g;
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import s from "./isHangfireResponse.mjs";
|
|
2
2
|
import "../api/isAcceptedResponse.mjs";
|
|
3
|
-
function
|
|
4
|
-
return `${
|
|
3
|
+
function c(r, t) {
|
|
4
|
+
return `${r.config.baseURL ?? ""}/${r.config.url ?? ""}/status/${t}`;
|
|
5
5
|
}
|
|
6
|
-
function
|
|
7
|
-
return async function(
|
|
8
|
-
const
|
|
9
|
-
if (s(
|
|
10
|
-
const
|
|
11
|
-
return
|
|
12
|
-
workerId:
|
|
13
|
-
url:
|
|
6
|
+
function l(r) {
|
|
7
|
+
return async function(o, i, u, f, n = {}) {
|
|
8
|
+
const e = await o(i, u, n);
|
|
9
|
+
if (s(e)) {
|
|
10
|
+
const a = e.data.id;
|
|
11
|
+
return r.createWorker(f, {
|
|
12
|
+
workerId: a,
|
|
13
|
+
url: c(e, a),
|
|
14
|
+
headers: n
|
|
14
15
|
});
|
|
15
16
|
}
|
|
16
|
-
return
|
|
17
|
+
return e;
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
20
|
export {
|
|
20
|
-
|
|
21
|
+
l as default
|
|
21
22
|
};
|