@io-orkes/conductor-javascript 1.2.3 → 2.0.0-rc2
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/README.md +0 -1
- package/dist/index.d.mts +2199 -3
- package/dist/index.d.ts +2199 -3
- package/dist/index.js +683 -545
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +683 -546
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -17
- package/dist/browser.d.mts +0 -13
- package/dist/browser.d.ts +0 -13
- package/dist/browser.js +0 -3648
- package/dist/browser.js.map +0 -1
- package/dist/browser.mjs +0 -3552
- package/dist/browser.mjs.map +0 -1
- package/dist/types-f83aa26f.d.ts +0 -2186
package/dist/index.js
CHANGED
|
@@ -53,6 +53,7 @@ __export(conductor_javascript_exports, {
|
|
|
53
53
|
WorkflowExecutor: () => WorkflowExecutor,
|
|
54
54
|
WorkflowResourceService: () => WorkflowResourceService,
|
|
55
55
|
baseOrkesConductorClient: () => baseOrkesConductorClient,
|
|
56
|
+
completedTaskMatchingType: () => completedTaskMatchingType,
|
|
56
57
|
conductorEventTask: () => conductorEventTask,
|
|
57
58
|
doWhileTask: () => doWhileTask,
|
|
58
59
|
dynamicForkTask: () => dynamicForkTask,
|
|
@@ -106,16 +107,9 @@ var LOG_LEVELS = {
|
|
|
106
107
|
ERROR: 60
|
|
107
108
|
};
|
|
108
109
|
var DefaultLogger = class {
|
|
110
|
+
tags;
|
|
111
|
+
level;
|
|
109
112
|
constructor(config = {}) {
|
|
110
|
-
this.info = (...args) => {
|
|
111
|
-
this.log("INFO", ...args);
|
|
112
|
-
};
|
|
113
|
-
this.debug = (...args) => {
|
|
114
|
-
this.log("DEBUG", ...args);
|
|
115
|
-
};
|
|
116
|
-
this.error = (...args) => {
|
|
117
|
-
this.log("ERROR", ...args);
|
|
118
|
-
};
|
|
119
113
|
const { level, tags = [] } = config;
|
|
120
114
|
this.tags = tags;
|
|
121
115
|
if (level && level in LOG_LEVELS) {
|
|
@@ -137,6 +131,15 @@ var DefaultLogger = class {
|
|
|
137
131
|
console.log(name, ...this.tags, ...args);
|
|
138
132
|
}
|
|
139
133
|
}
|
|
134
|
+
info = (...args) => {
|
|
135
|
+
this.log("INFO", ...args);
|
|
136
|
+
};
|
|
137
|
+
debug = (...args) => {
|
|
138
|
+
this.log("DEBUG", ...args);
|
|
139
|
+
};
|
|
140
|
+
error = (...args) => {
|
|
141
|
+
this.log("ERROR", ...args);
|
|
142
|
+
};
|
|
140
143
|
};
|
|
141
144
|
var noopLogger = {
|
|
142
145
|
//eslint-disable-next-line
|
|
@@ -1587,6 +1590,11 @@ var WorkflowResourceService = class {
|
|
|
1587
1590
|
|
|
1588
1591
|
// src/common/open-api/core/ApiError.ts
|
|
1589
1592
|
var ApiError = class extends Error {
|
|
1593
|
+
url;
|
|
1594
|
+
status;
|
|
1595
|
+
statusText;
|
|
1596
|
+
body;
|
|
1597
|
+
request;
|
|
1590
1598
|
constructor(request3, response, message) {
|
|
1591
1599
|
super(message);
|
|
1592
1600
|
this.name = "ApiError";
|
|
@@ -1609,9 +1617,14 @@ var CancelError = class extends Error {
|
|
|
1609
1617
|
}
|
|
1610
1618
|
};
|
|
1611
1619
|
var CancelablePromise = class {
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1620
|
+
[Symbol.toStringTag];
|
|
1621
|
+
_isResolved;
|
|
1622
|
+
_isRejected;
|
|
1623
|
+
_isCancelled;
|
|
1624
|
+
_cancelHandlers;
|
|
1625
|
+
_promise;
|
|
1626
|
+
_resolve;
|
|
1627
|
+
_reject;
|
|
1615
1628
|
constructor(executor) {
|
|
1616
1629
|
this._isResolved = false;
|
|
1617
1630
|
this._isRejected = false;
|
|
@@ -1924,83 +1937,70 @@ var HumanTaskService = class {
|
|
|
1924
1937
|
this.httpRequest = httpRequest;
|
|
1925
1938
|
}
|
|
1926
1939
|
/**
|
|
1927
|
-
*
|
|
1928
|
-
* @param
|
|
1929
|
-
* @
|
|
1930
|
-
* @param assigneeType
|
|
1931
|
-
* @param claimedBy
|
|
1932
|
-
* @param taskName
|
|
1933
|
-
* @param freeText
|
|
1934
|
-
* @param includeInputOutput
|
|
1935
|
-
* @returns SearchResultHumanTaskEntry OK
|
|
1940
|
+
* If the workflow is disconnected from tasks, this API can be used to clean up (in bulk)
|
|
1941
|
+
* @param requestBody
|
|
1942
|
+
* @returns any OK
|
|
1936
1943
|
* @throws ApiError
|
|
1937
1944
|
*/
|
|
1938
|
-
|
|
1945
|
+
deleteTaskFromHumanTaskRecords(requestBody) {
|
|
1939
1946
|
return this.httpRequest.request({
|
|
1940
|
-
method: "
|
|
1941
|
-
url: "/human/tasks",
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
"assignee": assignee,
|
|
1945
|
-
"assigneeType": assigneeType,
|
|
1946
|
-
"claimedBy": claimedBy,
|
|
1947
|
-
"taskName": taskName,
|
|
1948
|
-
"freeText": freeText,
|
|
1949
|
-
"includeInputOutput": includeInputOutput
|
|
1950
|
-
}
|
|
1947
|
+
method: "DELETE",
|
|
1948
|
+
url: "/human/tasks/delete",
|
|
1949
|
+
body: requestBody,
|
|
1950
|
+
mediaType: "application/json"
|
|
1951
1951
|
});
|
|
1952
1952
|
}
|
|
1953
1953
|
/**
|
|
1954
|
-
*
|
|
1955
|
-
* @
|
|
1954
|
+
* If the workflow is disconnected from tasks, this API can be used to clean up
|
|
1955
|
+
* @param taskId
|
|
1956
|
+
* @returns any OK
|
|
1956
1957
|
* @throws ApiError
|
|
1957
1958
|
*/
|
|
1958
|
-
|
|
1959
|
+
deleteTaskFromHumanTaskRecords1(taskId) {
|
|
1959
1960
|
return this.httpRequest.request({
|
|
1960
|
-
method: "
|
|
1961
|
-
url: "/human/tasks/
|
|
1961
|
+
method: "DELETE",
|
|
1962
|
+
url: "/human/tasks/delete/{taskId}",
|
|
1963
|
+
path: {
|
|
1964
|
+
"taskId": taskId
|
|
1965
|
+
}
|
|
1962
1966
|
});
|
|
1963
1967
|
}
|
|
1964
1968
|
/**
|
|
1965
1969
|
* Search human tasks
|
|
1966
|
-
* @param
|
|
1967
|
-
* @
|
|
1968
|
-
* @param size
|
|
1969
|
-
* @param freeText
|
|
1970
|
-
* @param query
|
|
1971
|
-
* @param jsonQuery
|
|
1972
|
-
* @param includeInputOutput
|
|
1973
|
-
* @returns HTScrollableSearchResultHumanTaskEntry OK
|
|
1970
|
+
* @param requestBody
|
|
1971
|
+
* @returns HumanTaskSearchResult OK
|
|
1974
1972
|
* @throws ApiError
|
|
1975
1973
|
*/
|
|
1976
|
-
|
|
1974
|
+
search(requestBody) {
|
|
1977
1975
|
return this.httpRequest.request({
|
|
1978
|
-
method: "
|
|
1976
|
+
method: "POST",
|
|
1979
1977
|
url: "/human/tasks/search",
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
"start": start,
|
|
1983
|
-
"size": size,
|
|
1984
|
-
"freeText": freeText,
|
|
1985
|
-
"query": query,
|
|
1986
|
-
"jsonQuery": jsonQuery,
|
|
1987
|
-
"includeInputOutput": includeInputOutput
|
|
1988
|
-
}
|
|
1978
|
+
body: requestBody,
|
|
1979
|
+
mediaType: "application/json"
|
|
1989
1980
|
});
|
|
1990
1981
|
}
|
|
1991
1982
|
/**
|
|
1992
|
-
*
|
|
1993
|
-
* @param
|
|
1983
|
+
* Update task output, optionally complete
|
|
1984
|
+
* @param workflowId
|
|
1985
|
+
* @param taskRefName
|
|
1986
|
+
* @param requestBody
|
|
1987
|
+
* @param complete
|
|
1988
|
+
* @param iteration Populate this value if your task is in a loop and you want to update a specific iteration. If its not in a loop OR if you want to just update the latest iteration, leave this as empty
|
|
1994
1989
|
* @returns any OK
|
|
1995
1990
|
* @throws ApiError
|
|
1996
1991
|
*/
|
|
1997
|
-
|
|
1992
|
+
updateTaskOutputByRef(workflowId, taskRefName, requestBody, complete = false, iteration) {
|
|
1998
1993
|
return this.httpRequest.request({
|
|
1999
|
-
method: "
|
|
2000
|
-
url: "/human/tasks/
|
|
2001
|
-
|
|
2002
|
-
"
|
|
2003
|
-
|
|
1994
|
+
method: "POST",
|
|
1995
|
+
url: "/human/tasks/update/taskRef",
|
|
1996
|
+
query: {
|
|
1997
|
+
"workflowId": workflowId,
|
|
1998
|
+
"taskRefName": taskRefName,
|
|
1999
|
+
"complete": complete,
|
|
2000
|
+
"iteration": iteration
|
|
2001
|
+
},
|
|
2002
|
+
body: requestBody,
|
|
2003
|
+
mediaType: "application/json"
|
|
2004
2004
|
});
|
|
2005
2005
|
}
|
|
2006
2006
|
/**
|
|
@@ -2018,33 +2018,22 @@ var HumanTaskService = class {
|
|
|
2018
2018
|
}
|
|
2019
2019
|
});
|
|
2020
2020
|
}
|
|
2021
|
-
/**
|
|
2022
|
-
* Get human task action log entries by task id
|
|
2023
|
-
* @param taskId
|
|
2024
|
-
* @returns HumanTaskActionLogEntry OK
|
|
2025
|
-
* @throws ApiError
|
|
2026
|
-
*/
|
|
2027
|
-
getActionLogs(taskId) {
|
|
2028
|
-
return this.httpRequest.request({
|
|
2029
|
-
method: "GET",
|
|
2030
|
-
url: "/human/tasks/{taskId}/actionLogs",
|
|
2031
|
-
path: {
|
|
2032
|
-
"taskId": taskId
|
|
2033
|
-
}
|
|
2034
|
-
});
|
|
2035
|
-
}
|
|
2036
2021
|
/**
|
|
2037
2022
|
* Claim a task by authenticated Conductor user
|
|
2038
2023
|
* @param taskId
|
|
2024
|
+
* @param overrideAssignment
|
|
2039
2025
|
* @returns any OK
|
|
2040
2026
|
* @throws ApiError
|
|
2041
2027
|
*/
|
|
2042
|
-
claimTask(taskId) {
|
|
2028
|
+
claimTask(taskId, overrideAssignment = false) {
|
|
2043
2029
|
return this.httpRequest.request({
|
|
2044
2030
|
method: "POST",
|
|
2045
2031
|
url: "/human/tasks/{taskId}/claim",
|
|
2046
2032
|
path: {
|
|
2047
2033
|
"taskId": taskId
|
|
2034
|
+
},
|
|
2035
|
+
query: {
|
|
2036
|
+
"overrideAssignment": overrideAssignment
|
|
2048
2037
|
}
|
|
2049
2038
|
});
|
|
2050
2039
|
}
|
|
@@ -2052,16 +2041,20 @@ var HumanTaskService = class {
|
|
|
2052
2041
|
* Claim a task to an external user
|
|
2053
2042
|
* @param taskId
|
|
2054
2043
|
* @param userId
|
|
2044
|
+
* @param overrideAssignment
|
|
2055
2045
|
* @returns any OK
|
|
2056
2046
|
* @throws ApiError
|
|
2057
2047
|
*/
|
|
2058
|
-
assignAndClaim(taskId, userId) {
|
|
2048
|
+
assignAndClaim(taskId, userId, overrideAssignment = false) {
|
|
2059
2049
|
return this.httpRequest.request({
|
|
2060
2050
|
method: "POST",
|
|
2061
2051
|
url: "/human/tasks/{taskId}/externalUser/{userId}",
|
|
2062
2052
|
path: {
|
|
2063
2053
|
"taskId": taskId,
|
|
2064
2054
|
"userId": userId
|
|
2055
|
+
},
|
|
2056
|
+
query: {
|
|
2057
|
+
"overrideAssignment": overrideAssignment
|
|
2065
2058
|
}
|
|
2066
2059
|
});
|
|
2067
2060
|
}
|
|
@@ -2099,17 +2092,21 @@ var HumanTaskService = class {
|
|
|
2099
2092
|
});
|
|
2100
2093
|
}
|
|
2101
2094
|
/**
|
|
2102
|
-
*
|
|
2095
|
+
* If a task is assigned to a user, this API can be used to skip that assignment and move to the next assignee
|
|
2103
2096
|
* @param taskId
|
|
2104
|
-
* @
|
|
2097
|
+
* @param reason
|
|
2098
|
+
* @returns any OK
|
|
2105
2099
|
* @throws ApiError
|
|
2106
2100
|
*/
|
|
2107
|
-
|
|
2101
|
+
skipTask(taskId, reason) {
|
|
2108
2102
|
return this.httpRequest.request({
|
|
2109
|
-
method: "
|
|
2110
|
-
url: "/human/tasks/{taskId}/
|
|
2103
|
+
method: "POST",
|
|
2104
|
+
url: "/human/tasks/{taskId}/skip",
|
|
2111
2105
|
path: {
|
|
2112
2106
|
"taskId": taskId
|
|
2107
|
+
},
|
|
2108
|
+
query: {
|
|
2109
|
+
"reason": reason
|
|
2113
2110
|
}
|
|
2114
2111
|
});
|
|
2115
2112
|
}
|
|
@@ -2136,48 +2133,51 @@ var HumanTaskService = class {
|
|
|
2136
2133
|
});
|
|
2137
2134
|
}
|
|
2138
2135
|
/**
|
|
2139
|
-
*
|
|
2136
|
+
* List all user form templates or get templates by name, or a template by name and version
|
|
2140
2137
|
* @param name
|
|
2141
|
-
* @
|
|
2138
|
+
* @param version
|
|
2139
|
+
* @returns HumanTaskTemplate OK
|
|
2142
2140
|
* @throws ApiError
|
|
2143
2141
|
*/
|
|
2144
|
-
|
|
2142
|
+
getAllTemplates(name, version) {
|
|
2145
2143
|
return this.httpRequest.request({
|
|
2146
|
-
method: "
|
|
2144
|
+
method: "GET",
|
|
2147
2145
|
url: "/human/template",
|
|
2148
2146
|
query: {
|
|
2149
|
-
"name": name
|
|
2147
|
+
"name": name,
|
|
2148
|
+
"version": version
|
|
2150
2149
|
}
|
|
2151
2150
|
});
|
|
2152
2151
|
}
|
|
2153
2152
|
/**
|
|
2154
|
-
*
|
|
2155
|
-
* @param
|
|
2156
|
-
* @param
|
|
2157
|
-
* @returns
|
|
2153
|
+
* Save user form template
|
|
2154
|
+
* @param requestBody
|
|
2155
|
+
* @param newVersion
|
|
2156
|
+
* @returns HumanTaskTemplate OK
|
|
2158
2157
|
* @throws ApiError
|
|
2159
2158
|
*/
|
|
2160
|
-
|
|
2159
|
+
saveTemplate(requestBody, newVersion = false) {
|
|
2161
2160
|
return this.httpRequest.request({
|
|
2162
|
-
method: "
|
|
2161
|
+
method: "POST",
|
|
2163
2162
|
url: "/human/template",
|
|
2164
2163
|
query: {
|
|
2165
|
-
"
|
|
2166
|
-
|
|
2167
|
-
|
|
2164
|
+
"newVersion": newVersion
|
|
2165
|
+
},
|
|
2166
|
+
body: requestBody,
|
|
2167
|
+
mediaType: "application/json"
|
|
2168
2168
|
});
|
|
2169
2169
|
}
|
|
2170
2170
|
/**
|
|
2171
|
-
* Save
|
|
2171
|
+
* Save user form template
|
|
2172
2172
|
* @param requestBody
|
|
2173
2173
|
* @param newVersion
|
|
2174
|
-
* @returns
|
|
2174
|
+
* @returns HumanTaskTemplate OK
|
|
2175
2175
|
* @throws ApiError
|
|
2176
2176
|
*/
|
|
2177
|
-
|
|
2177
|
+
saveTemplates(requestBody, newVersion = false) {
|
|
2178
2178
|
return this.httpRequest.request({
|
|
2179
2179
|
method: "POST",
|
|
2180
|
-
url: "/human/template",
|
|
2180
|
+
url: "/human/template/bulk",
|
|
2181
2181
|
query: {
|
|
2182
2182
|
"newVersion": newVersion
|
|
2183
2183
|
},
|
|
@@ -2186,32 +2186,51 @@ var HumanTaskService = class {
|
|
|
2186
2186
|
});
|
|
2187
2187
|
}
|
|
2188
2188
|
/**
|
|
2189
|
-
* Delete
|
|
2190
|
-
* @param
|
|
2189
|
+
* Delete all versions of user form template by name
|
|
2190
|
+
* @param name
|
|
2191
|
+
* @returns any OK
|
|
2192
|
+
* @throws ApiError
|
|
2193
|
+
*/
|
|
2194
|
+
deleteTemplateByName(name) {
|
|
2195
|
+
return this.httpRequest.request({
|
|
2196
|
+
method: "DELETE",
|
|
2197
|
+
url: "/human/template/{name}",
|
|
2198
|
+
path: {
|
|
2199
|
+
"name": name
|
|
2200
|
+
}
|
|
2201
|
+
});
|
|
2202
|
+
}
|
|
2203
|
+
/**
|
|
2204
|
+
* Delete a version of form template by name
|
|
2205
|
+
* @param name
|
|
2206
|
+
* @param version
|
|
2191
2207
|
* @returns any OK
|
|
2192
2208
|
* @throws ApiError
|
|
2193
2209
|
*/
|
|
2194
|
-
|
|
2210
|
+
deleteTemplatesByNameAndVersion(name, version) {
|
|
2195
2211
|
return this.httpRequest.request({
|
|
2196
2212
|
method: "DELETE",
|
|
2197
|
-
url: "/human/template/{
|
|
2213
|
+
url: "/human/template/{name}/{version}",
|
|
2198
2214
|
path: {
|
|
2199
|
-
"
|
|
2215
|
+
"name": name,
|
|
2216
|
+
"version": version
|
|
2200
2217
|
}
|
|
2201
2218
|
});
|
|
2202
2219
|
}
|
|
2203
2220
|
/**
|
|
2204
|
-
* Get
|
|
2205
|
-
* @param
|
|
2206
|
-
* @
|
|
2221
|
+
* Get user form template by name and version
|
|
2222
|
+
* @param name
|
|
2223
|
+
* @param version
|
|
2224
|
+
* @returns HumanTaskTemplate OK
|
|
2207
2225
|
* @throws ApiError
|
|
2208
2226
|
*/
|
|
2209
|
-
|
|
2227
|
+
getTemplateByNameAndVersion(name, version) {
|
|
2210
2228
|
return this.httpRequest.request({
|
|
2211
2229
|
method: "GET",
|
|
2212
|
-
url: "/human/template/{
|
|
2230
|
+
url: "/human/template/{name}/{version}",
|
|
2213
2231
|
path: {
|
|
2214
|
-
"
|
|
2232
|
+
"name": name,
|
|
2233
|
+
"version": version
|
|
2215
2234
|
}
|
|
2216
2235
|
});
|
|
2217
2236
|
}
|
|
@@ -2242,6 +2261,18 @@ var HumanTaskResourceService = class {
|
|
|
2242
2261
|
// src/common/open-api/ConductorClient.ts
|
|
2243
2262
|
var defaultRequestHandler = (request3, config, options) => request3(config, options);
|
|
2244
2263
|
var ConductorClient = class {
|
|
2264
|
+
eventResource;
|
|
2265
|
+
healthCheckResource;
|
|
2266
|
+
metadataResource;
|
|
2267
|
+
schedulerResource;
|
|
2268
|
+
taskResource;
|
|
2269
|
+
tokenResource;
|
|
2270
|
+
workflowBulkResource;
|
|
2271
|
+
workflowResource;
|
|
2272
|
+
humanTask;
|
|
2273
|
+
humanTaskResource;
|
|
2274
|
+
request;
|
|
2275
|
+
token;
|
|
2245
2276
|
constructor(config, requestHandler = defaultRequestHandler) {
|
|
2246
2277
|
const resolvedConfig = {
|
|
2247
2278
|
BASE: config?.serverUrl ?? "http://localhost:8080",
|
|
@@ -2295,75 +2326,21 @@ var DEFAULT_BATCH_POLLING_TIMEOUT = 100;
|
|
|
2295
2326
|
|
|
2296
2327
|
// src/task/Poller.ts
|
|
2297
2328
|
var Poller = class {
|
|
2329
|
+
timeoutHandler;
|
|
2330
|
+
pollFunction;
|
|
2331
|
+
performWorkFunction = async () => {
|
|
2332
|
+
};
|
|
2333
|
+
polling = false;
|
|
2334
|
+
_tasksInProcess = 0;
|
|
2335
|
+
_counterAtO = 0;
|
|
2336
|
+
_pollerId = "";
|
|
2337
|
+
options = {
|
|
2338
|
+
pollInterval: DEFAULT_POLL_INTERVAL,
|
|
2339
|
+
concurrency: DEFAULT_CONCURRENCY,
|
|
2340
|
+
warnAtO: DEFAULT_WARN_AT_O
|
|
2341
|
+
};
|
|
2342
|
+
logger = noopLogger;
|
|
2298
2343
|
constructor(pollerId, pollFunction, performWorkFunction, pollerOptions, logger) {
|
|
2299
|
-
this.performWorkFunction = async () => {
|
|
2300
|
-
};
|
|
2301
|
-
this.polling = false;
|
|
2302
|
-
this._tasksInProcess = 0;
|
|
2303
|
-
this._counterAtO = 0;
|
|
2304
|
-
this._pollerId = "";
|
|
2305
|
-
this.options = {
|
|
2306
|
-
pollInterval: DEFAULT_POLL_INTERVAL,
|
|
2307
|
-
concurrency: DEFAULT_CONCURRENCY,
|
|
2308
|
-
warnAtO: DEFAULT_WARN_AT_O
|
|
2309
|
-
};
|
|
2310
|
-
this.logger = noopLogger;
|
|
2311
|
-
/**
|
|
2312
|
-
* Starts polling for work
|
|
2313
|
-
*/
|
|
2314
|
-
this.startPolling = () => {
|
|
2315
|
-
if (this.polling) {
|
|
2316
|
-
throw new Error("Runner is already started");
|
|
2317
|
-
}
|
|
2318
|
-
this._tasksInProcess = 0;
|
|
2319
|
-
this.polling = true;
|
|
2320
|
-
this.poll();
|
|
2321
|
-
};
|
|
2322
|
-
/**
|
|
2323
|
-
* Stops Polling for work
|
|
2324
|
-
*/
|
|
2325
|
-
this.stopPolling = async () => {
|
|
2326
|
-
this.polling = false;
|
|
2327
|
-
clearTimeout(this.timeoutHandler);
|
|
2328
|
-
};
|
|
2329
|
-
this.performWork = async (work) => {
|
|
2330
|
-
await this.performWorkFunction(work);
|
|
2331
|
-
this._tasksInProcess--;
|
|
2332
|
-
};
|
|
2333
|
-
this.poll = async () => {
|
|
2334
|
-
while (this.isPolling) {
|
|
2335
|
-
try {
|
|
2336
|
-
const count = Math.max(
|
|
2337
|
-
0,
|
|
2338
|
-
this.options.concurrency - this._tasksInProcess
|
|
2339
|
-
);
|
|
2340
|
-
if (count === 0) {
|
|
2341
|
-
this.logger.debug(
|
|
2342
|
-
"Max in process reached, Will skip polling for " + this._pollerId
|
|
2343
|
-
);
|
|
2344
|
-
this._counterAtO++;
|
|
2345
|
-
if (this._counterAtO > (this.options.warnAtO ?? 100)) {
|
|
2346
|
-
this.logger.info(
|
|
2347
|
-
`Not polling anything because in process tasks is maxed as concurrency level. ${this._pollerId}`
|
|
2348
|
-
);
|
|
2349
|
-
}
|
|
2350
|
-
} else {
|
|
2351
|
-
this._counterAtO = 0;
|
|
2352
|
-
const tasksResult = await this.pollFunction(count);
|
|
2353
|
-
this._tasksInProcess = this._tasksInProcess + (tasksResult ?? []).length;
|
|
2354
|
-
tasksResult.forEach(this.performWork);
|
|
2355
|
-
}
|
|
2356
|
-
} catch (e) {
|
|
2357
|
-
this.logger.error(`Error polling for tasks: ${e.message}`, e);
|
|
2358
|
-
}
|
|
2359
|
-
await new Promise(
|
|
2360
|
-
(r) => this.isPolling ? this.timeoutHandler = setTimeout(
|
|
2361
|
-
() => r(true),
|
|
2362
|
-
this.options.pollInterval
|
|
2363
|
-
) : r(true)
|
|
2364
|
-
);
|
|
2365
|
-
}
|
|
2366
|
-
};
|
|
2367
2344
|
this._pollerId = pollerId;
|
|
2368
2345
|
this.pollFunction = pollFunction;
|
|
2369
2346
|
this.performWorkFunction = performWorkFunction;
|
|
@@ -2376,10 +2353,66 @@ var Poller = class {
|
|
|
2376
2353
|
get tasksInProcess() {
|
|
2377
2354
|
return this._tasksInProcess;
|
|
2378
2355
|
}
|
|
2356
|
+
/**
|
|
2357
|
+
* Starts polling for work
|
|
2358
|
+
*/
|
|
2359
|
+
startPolling = () => {
|
|
2360
|
+
if (this.polling) {
|
|
2361
|
+
throw new Error("Runner is already started");
|
|
2362
|
+
}
|
|
2363
|
+
this._tasksInProcess = 0;
|
|
2364
|
+
this.polling = true;
|
|
2365
|
+
this.poll();
|
|
2366
|
+
};
|
|
2367
|
+
/**
|
|
2368
|
+
* Stops Polling for work
|
|
2369
|
+
*/
|
|
2370
|
+
stopPolling = async () => {
|
|
2371
|
+
this.polling = false;
|
|
2372
|
+
clearTimeout(this.timeoutHandler);
|
|
2373
|
+
};
|
|
2374
|
+
performWork = async (work) => {
|
|
2375
|
+
await this.performWorkFunction(work);
|
|
2376
|
+
this._tasksInProcess--;
|
|
2377
|
+
};
|
|
2379
2378
|
updateOptions(options) {
|
|
2380
2379
|
const newOptions = { ...this.options, ...options };
|
|
2381
2380
|
this.options = newOptions;
|
|
2382
2381
|
}
|
|
2382
|
+
poll = async () => {
|
|
2383
|
+
while (this.isPolling) {
|
|
2384
|
+
try {
|
|
2385
|
+
const count = Math.max(
|
|
2386
|
+
0,
|
|
2387
|
+
this.options.concurrency - this._tasksInProcess
|
|
2388
|
+
);
|
|
2389
|
+
if (count === 0) {
|
|
2390
|
+
this.logger.debug(
|
|
2391
|
+
"Max in process reached, Will skip polling for " + this._pollerId
|
|
2392
|
+
);
|
|
2393
|
+
this._counterAtO++;
|
|
2394
|
+
if (this._counterAtO > (this.options.warnAtO ?? 100)) {
|
|
2395
|
+
this.logger.info(
|
|
2396
|
+
`Not polling anything because in process tasks is maxed as concurrency level. ${this._pollerId}`
|
|
2397
|
+
);
|
|
2398
|
+
}
|
|
2399
|
+
} else {
|
|
2400
|
+
this._counterAtO = 0;
|
|
2401
|
+
const tasksResult = await this.pollFunction(count);
|
|
2402
|
+
this._tasksInProcess = this._tasksInProcess + (tasksResult ?? []).length;
|
|
2403
|
+
tasksResult.forEach(this.performWork);
|
|
2404
|
+
}
|
|
2405
|
+
} catch (e) {
|
|
2406
|
+
this.logger.error(`Error polling for tasks: ${e.message}`, e);
|
|
2407
|
+
}
|
|
2408
|
+
await new Promise(
|
|
2409
|
+
(r) => this.isPolling ? this.timeoutHandler = setTimeout(
|
|
2410
|
+
() => r(true),
|
|
2411
|
+
this.options.pollInterval
|
|
2412
|
+
) : r(true)
|
|
2413
|
+
);
|
|
2414
|
+
}
|
|
2415
|
+
};
|
|
2383
2416
|
};
|
|
2384
2417
|
|
|
2385
2418
|
// src/task/helpers.ts
|
|
@@ -2404,6 +2437,12 @@ var defaultRunnerOptions = {
|
|
|
2404
2437
|
batchPollingTimeout: DEFAULT_BATCH_POLLING_TIMEOUT
|
|
2405
2438
|
};
|
|
2406
2439
|
var TaskRunner = class {
|
|
2440
|
+
taskResource;
|
|
2441
|
+
worker;
|
|
2442
|
+
logger;
|
|
2443
|
+
options;
|
|
2444
|
+
errorHandler;
|
|
2445
|
+
poller;
|
|
2407
2446
|
constructor({
|
|
2408
2447
|
worker,
|
|
2409
2448
|
taskResource,
|
|
@@ -2411,91 +2450,6 @@ var TaskRunner = class {
|
|
|
2411
2450
|
logger = noopLogger,
|
|
2412
2451
|
onError: errorHandler = noopErrorHandler
|
|
2413
2452
|
}) {
|
|
2414
|
-
/**
|
|
2415
|
-
* Starts polling for work
|
|
2416
|
-
*/
|
|
2417
|
-
this.startPolling = () => {
|
|
2418
|
-
this.poller.startPolling();
|
|
2419
|
-
this.logger.info(
|
|
2420
|
-
`TaskWorker ${this.worker.taskDefName} initialized with concurrency of ${this.poller.options.concurrency} and poll interval of ${this.poller.options.pollInterval}`
|
|
2421
|
-
);
|
|
2422
|
-
};
|
|
2423
|
-
/**
|
|
2424
|
-
* Stops Polling for work
|
|
2425
|
-
*/
|
|
2426
|
-
this.stopPolling = async () => {
|
|
2427
|
-
await this.poller.stopPolling();
|
|
2428
|
-
};
|
|
2429
|
-
this.batchPoll = async (count) => {
|
|
2430
|
-
const { workerID } = this.options;
|
|
2431
|
-
const tasks = await this.taskResource.batchPoll(
|
|
2432
|
-
this.worker.taskDefName,
|
|
2433
|
-
workerID,
|
|
2434
|
-
this.worker.domain ?? this.options.domain,
|
|
2435
|
-
count,
|
|
2436
|
-
this.options.batchPollingTimeout ?? 100
|
|
2437
|
-
// default batch poll defined in the method
|
|
2438
|
-
);
|
|
2439
|
-
return tasks;
|
|
2440
|
-
};
|
|
2441
|
-
this.updateTaskWithRetry = async (task, taskResult) => {
|
|
2442
|
-
const { workerID } = this.options;
|
|
2443
|
-
let retryCount = 0;
|
|
2444
|
-
while (retryCount < MAX_RETRIES) {
|
|
2445
|
-
try {
|
|
2446
|
-
await this.taskResource.updateTask1({
|
|
2447
|
-
...taskResult,
|
|
2448
|
-
workerId: workerID
|
|
2449
|
-
});
|
|
2450
|
-
return;
|
|
2451
|
-
} catch (error) {
|
|
2452
|
-
this.errorHandler(error, task);
|
|
2453
|
-
this.logger.error(
|
|
2454
|
-
`Error updating task ${taskResult.taskId} on retry ${retryCount}`,
|
|
2455
|
-
error
|
|
2456
|
-
);
|
|
2457
|
-
retryCount++;
|
|
2458
|
-
await new Promise((r) => setTimeout(() => r(true), retryCount * 10));
|
|
2459
|
-
}
|
|
2460
|
-
}
|
|
2461
|
-
this.logger.error(
|
|
2462
|
-
`Unable to update task ${taskResult.taskId} after ${retryCount} retries`
|
|
2463
|
-
);
|
|
2464
|
-
};
|
|
2465
|
-
this.executeTask = async (task) => {
|
|
2466
|
-
try {
|
|
2467
|
-
const result = await this.worker.execute(task);
|
|
2468
|
-
await this.updateTaskWithRetry(task, {
|
|
2469
|
-
...result,
|
|
2470
|
-
workflowInstanceId: task.workflowInstanceId,
|
|
2471
|
-
taskId: task.taskId
|
|
2472
|
-
});
|
|
2473
|
-
this.logger.debug(`Task has executed successfully ${task.taskId}`);
|
|
2474
|
-
} catch (error) {
|
|
2475
|
-
await this.updateTaskWithRetry(task, {
|
|
2476
|
-
workflowInstanceId: task.workflowInstanceId,
|
|
2477
|
-
taskId: task.taskId,
|
|
2478
|
-
reasonForIncompletion: error?.message ?? DEFAULT_ERROR_MESSAGE,
|
|
2479
|
-
status: "FAILED",
|
|
2480
|
-
outputData: {}
|
|
2481
|
-
});
|
|
2482
|
-
this.errorHandler(error, task);
|
|
2483
|
-
this.logger.error(`Error executing ${task.taskId}`, error);
|
|
2484
|
-
}
|
|
2485
|
-
};
|
|
2486
|
-
this.handleUnknownError = (unknownError) => {
|
|
2487
|
-
let message = "";
|
|
2488
|
-
let stack = "";
|
|
2489
|
-
if (unknownError.stack) {
|
|
2490
|
-
stack = unknownError.stack;
|
|
2491
|
-
}
|
|
2492
|
-
if (unknownError.message) {
|
|
2493
|
-
message = unknownError.message;
|
|
2494
|
-
}
|
|
2495
|
-
this.logger.error(
|
|
2496
|
-
`Error for ${this.worker.taskDefName}: error: ${message}, stack: ${stack}`
|
|
2497
|
-
);
|
|
2498
|
-
};
|
|
2499
2453
|
this.taskResource = taskResource;
|
|
2500
2454
|
this.logger = logger;
|
|
2501
2455
|
this.worker = worker;
|
|
@@ -2515,6 +2469,21 @@ var TaskRunner = class {
|
|
|
2515
2469
|
get isPolling() {
|
|
2516
2470
|
return this.poller.isPolling;
|
|
2517
2471
|
}
|
|
2472
|
+
/**
|
|
2473
|
+
* Starts polling for work
|
|
2474
|
+
*/
|
|
2475
|
+
startPolling = () => {
|
|
2476
|
+
this.poller.startPolling();
|
|
2477
|
+
this.logger.info(
|
|
2478
|
+
`TaskWorker ${this.worker.taskDefName} initialized with concurrency of ${this.poller.options.concurrency} and poll interval of ${this.poller.options.pollInterval}`
|
|
2479
|
+
);
|
|
2480
|
+
};
|
|
2481
|
+
/**
|
|
2482
|
+
* Stops Polling for work
|
|
2483
|
+
*/
|
|
2484
|
+
stopPolling = async () => {
|
|
2485
|
+
await this.poller.stopPolling();
|
|
2486
|
+
};
|
|
2518
2487
|
updateOptions(options) {
|
|
2519
2488
|
const newOptions = { ...this.options, ...options };
|
|
2520
2489
|
const isOptionsUpdated = !optionEquals(this.options, newOptions);
|
|
@@ -2532,6 +2501,76 @@ var TaskRunner = class {
|
|
|
2532
2501
|
get getOptions() {
|
|
2533
2502
|
return this.options;
|
|
2534
2503
|
}
|
|
2504
|
+
batchPoll = async (count) => {
|
|
2505
|
+
const { workerID } = this.options;
|
|
2506
|
+
const tasks = await this.taskResource.batchPoll(
|
|
2507
|
+
this.worker.taskDefName,
|
|
2508
|
+
workerID,
|
|
2509
|
+
this.worker.domain ?? this.options.domain,
|
|
2510
|
+
count,
|
|
2511
|
+
this.options.batchPollingTimeout ?? 100
|
|
2512
|
+
// default batch poll defined in the method
|
|
2513
|
+
);
|
|
2514
|
+
return tasks;
|
|
2515
|
+
};
|
|
2516
|
+
updateTaskWithRetry = async (task, taskResult) => {
|
|
2517
|
+
const { workerID } = this.options;
|
|
2518
|
+
let retryCount = 0;
|
|
2519
|
+
while (retryCount < MAX_RETRIES) {
|
|
2520
|
+
try {
|
|
2521
|
+
await this.taskResource.updateTask1({
|
|
2522
|
+
...taskResult,
|
|
2523
|
+
workerId: workerID
|
|
2524
|
+
});
|
|
2525
|
+
return;
|
|
2526
|
+
} catch (error) {
|
|
2527
|
+
this.errorHandler(error, task);
|
|
2528
|
+
this.logger.error(
|
|
2529
|
+
`Error updating task ${taskResult.taskId} on retry ${retryCount}`,
|
|
2530
|
+
error
|
|
2531
|
+
);
|
|
2532
|
+
retryCount++;
|
|
2533
|
+
await new Promise((r) => setTimeout(() => r(true), retryCount * 10));
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2536
|
+
this.logger.error(
|
|
2537
|
+
`Unable to update task ${taskResult.taskId} after ${retryCount} retries`
|
|
2538
|
+
);
|
|
2539
|
+
};
|
|
2540
|
+
executeTask = async (task) => {
|
|
2541
|
+
try {
|
|
2542
|
+
const result = await this.worker.execute(task);
|
|
2543
|
+
await this.updateTaskWithRetry(task, {
|
|
2544
|
+
...result,
|
|
2545
|
+
workflowInstanceId: task.workflowInstanceId,
|
|
2546
|
+
taskId: task.taskId
|
|
2547
|
+
});
|
|
2548
|
+
this.logger.debug(`Task has executed successfully ${task.taskId}`);
|
|
2549
|
+
} catch (error) {
|
|
2550
|
+
await this.updateTaskWithRetry(task, {
|
|
2551
|
+
workflowInstanceId: task.workflowInstanceId,
|
|
2552
|
+
taskId: task.taskId,
|
|
2553
|
+
reasonForIncompletion: error?.message ?? DEFAULT_ERROR_MESSAGE,
|
|
2554
|
+
status: "FAILED",
|
|
2555
|
+
outputData: {}
|
|
2556
|
+
});
|
|
2557
|
+
this.errorHandler(error, task);
|
|
2558
|
+
this.logger.error(`Error executing ${task.taskId}`, error);
|
|
2559
|
+
}
|
|
2560
|
+
};
|
|
2561
|
+
handleUnknownError = (unknownError) => {
|
|
2562
|
+
let message = "";
|
|
2563
|
+
let stack = "";
|
|
2564
|
+
if (unknownError.stack) {
|
|
2565
|
+
stack = unknownError.stack;
|
|
2566
|
+
}
|
|
2567
|
+
if (unknownError.message) {
|
|
2568
|
+
message = unknownError.message;
|
|
2569
|
+
}
|
|
2570
|
+
this.logger.error(
|
|
2571
|
+
`Error for ${this.worker.taskDefName}: error: ${message}, stack: ${stack}`
|
|
2572
|
+
);
|
|
2573
|
+
};
|
|
2535
2574
|
};
|
|
2536
2575
|
|
|
2537
2576
|
// src/task/TaskManager.ts
|
|
@@ -2547,84 +2586,14 @@ function workerId(options) {
|
|
|
2547
2586
|
return options.workerID ?? import_os.default.hostname();
|
|
2548
2587
|
}
|
|
2549
2588
|
var TaskManager = class {
|
|
2589
|
+
workerRunners = /* @__PURE__ */ new Map();
|
|
2590
|
+
client;
|
|
2591
|
+
logger;
|
|
2592
|
+
errorHandler;
|
|
2593
|
+
workers;
|
|
2594
|
+
options;
|
|
2595
|
+
polling = false;
|
|
2550
2596
|
constructor(client, workers, config = {}) {
|
|
2551
|
-
this.workerRunners = /* @__PURE__ */ new Map();
|
|
2552
|
-
this.polling = false;
|
|
2553
|
-
this.workerManagerWorkerOptions = (worker) => {
|
|
2554
|
-
return {
|
|
2555
|
-
...this.options,
|
|
2556
|
-
concurrency: worker.concurrency ?? this.options.concurrency,
|
|
2557
|
-
pollInterval: worker.pollInterval ?? this.options.pollInterval,
|
|
2558
|
-
domain: worker.domain ?? this.options.domain
|
|
2559
|
-
};
|
|
2560
|
-
};
|
|
2561
|
-
this.updatePollingOptionForWorker = (workerTaskDefName, options) => {
|
|
2562
|
-
const maybeRunner = this.workerRunners.get(workerTaskDefName);
|
|
2563
|
-
if (maybeRunner != null) {
|
|
2564
|
-
maybeRunner.updateOptions(options);
|
|
2565
|
-
} else {
|
|
2566
|
-
this.logger.info(
|
|
2567
|
-
`No runner found for worker with taskDefName: ${workerTaskDefName}`
|
|
2568
|
-
);
|
|
2569
|
-
}
|
|
2570
|
-
};
|
|
2571
|
-
/**
|
|
2572
|
-
* new options will get merged to existing options
|
|
2573
|
-
* @param options new options to update polling options
|
|
2574
|
-
*/
|
|
2575
|
-
this.updatePollingOptions = (options) => {
|
|
2576
|
-
this.workers.forEach((worker) => {
|
|
2577
|
-
const newOptions = {
|
|
2578
|
-
...this.workerManagerWorkerOptions(worker),
|
|
2579
|
-
...options
|
|
2580
|
-
};
|
|
2581
|
-
this.updatePollingOptionForWorker(worker.taskDefName, newOptions);
|
|
2582
|
-
});
|
|
2583
|
-
this.options.concurrency = options.concurrency ?? this.options.concurrency;
|
|
2584
|
-
this.options.pollInterval = options.pollInterval ?? this.options.pollInterval;
|
|
2585
|
-
};
|
|
2586
|
-
this.sanityCheck = () => {
|
|
2587
|
-
if (this.workers.length === 0) {
|
|
2588
|
-
throw new Error("No workers supplied to TaskManager");
|
|
2589
|
-
}
|
|
2590
|
-
const workerIDs = /* @__PURE__ */ new Set();
|
|
2591
|
-
for (const item of this.workers) {
|
|
2592
|
-
if (workerIDs.has(item.taskDefName)) {
|
|
2593
|
-
throw new Error(`Duplicate worker taskDefName: ${item.taskDefName}`);
|
|
2594
|
-
}
|
|
2595
|
-
workerIDs.add(item.taskDefName);
|
|
2596
|
-
}
|
|
2597
|
-
};
|
|
2598
|
-
/**
|
|
2599
|
-
* Start polling for tasks
|
|
2600
|
-
*/
|
|
2601
|
-
this.startPolling = () => {
|
|
2602
|
-
this.sanityCheck();
|
|
2603
|
-
this.workers.forEach((worker) => {
|
|
2604
|
-
const options = this.workerManagerWorkerOptions(worker);
|
|
2605
|
-
const runner = new TaskRunner({
|
|
2606
|
-
worker,
|
|
2607
|
-
options,
|
|
2608
|
-
taskResource: this.client.taskResource,
|
|
2609
|
-
logger: this.logger,
|
|
2610
|
-
onError: this.errorHandler
|
|
2611
|
-
});
|
|
2612
|
-
runner.startPolling();
|
|
2613
|
-
this.workerRunners.set(worker.taskDefName, runner);
|
|
2614
|
-
});
|
|
2615
|
-
this.polling = true;
|
|
2616
|
-
};
|
|
2617
|
-
/**
|
|
2618
|
-
* Stops polling for tasks
|
|
2619
|
-
*/
|
|
2620
|
-
this.stopPolling = async () => {
|
|
2621
|
-
for (const [workerTaskDefName, runner] of this.workerRunners) {
|
|
2622
|
-
this.logger.debug(`Stopping taskDefName=${workerTaskDefName}`);
|
|
2623
|
-
await runner.stopPolling();
|
|
2624
|
-
this.workerRunners.delete(workerTaskDefName);
|
|
2625
|
-
}
|
|
2626
|
-
this.polling = false;
|
|
2627
|
-
};
|
|
2628
2597
|
if (!workers) {
|
|
2629
2598
|
throw new Error(
|
|
2630
2599
|
"No workers supplied to TaskManager. Please pass an array of workers."
|
|
@@ -2641,19 +2610,96 @@ var TaskManager = class {
|
|
|
2641
2610
|
workerID: workerId(providedOptions)
|
|
2642
2611
|
};
|
|
2643
2612
|
}
|
|
2613
|
+
workerManagerWorkerOptions = (worker) => {
|
|
2614
|
+
return {
|
|
2615
|
+
...this.options,
|
|
2616
|
+
concurrency: worker.concurrency ?? this.options.concurrency,
|
|
2617
|
+
pollInterval: worker.pollInterval ?? this.options.pollInterval,
|
|
2618
|
+
domain: worker.domain ?? this.options.domain
|
|
2619
|
+
};
|
|
2620
|
+
};
|
|
2644
2621
|
get isPolling() {
|
|
2645
2622
|
return this.polling;
|
|
2646
2623
|
}
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2624
|
+
updatePollingOptionForWorker = (workerTaskDefName, options) => {
|
|
2625
|
+
const maybeRunner = this.workerRunners.get(workerTaskDefName);
|
|
2626
|
+
if (maybeRunner != null) {
|
|
2627
|
+
maybeRunner.updateOptions(options);
|
|
2628
|
+
} else {
|
|
2629
|
+
this.logger.info(
|
|
2630
|
+
`No runner found for worker with taskDefName: ${workerTaskDefName}`
|
|
2631
|
+
);
|
|
2632
|
+
}
|
|
2633
|
+
};
|
|
2634
|
+
/**
|
|
2635
|
+
* new options will get merged to existing options
|
|
2636
|
+
* @param options new options to update polling options
|
|
2637
|
+
*/
|
|
2638
|
+
updatePollingOptions = (options) => {
|
|
2639
|
+
this.workers.forEach((worker) => {
|
|
2640
|
+
const newOptions = {
|
|
2641
|
+
...this.workerManagerWorkerOptions(worker),
|
|
2642
|
+
...options
|
|
2643
|
+
};
|
|
2644
|
+
this.updatePollingOptionForWorker(worker.taskDefName, newOptions);
|
|
2645
|
+
});
|
|
2646
|
+
this.options.concurrency = options.concurrency ?? this.options.concurrency;
|
|
2647
|
+
this.options.pollInterval = options.pollInterval ?? this.options.pollInterval;
|
|
2648
|
+
};
|
|
2649
|
+
sanityCheck = () => {
|
|
2650
|
+
if (this.workers.length === 0) {
|
|
2651
|
+
throw new Error("No workers supplied to TaskManager");
|
|
2652
|
+
}
|
|
2653
|
+
const workerIDs = /* @__PURE__ */ new Set();
|
|
2654
|
+
for (const item of this.workers) {
|
|
2655
|
+
if (workerIDs.has(item.taskDefName)) {
|
|
2656
|
+
throw new Error(`Duplicate worker taskDefName: ${item.taskDefName}`);
|
|
2657
|
+
}
|
|
2658
|
+
workerIDs.add(item.taskDefName);
|
|
2659
|
+
}
|
|
2660
|
+
};
|
|
2661
|
+
/**
|
|
2662
|
+
* Start polling for tasks
|
|
2663
|
+
*/
|
|
2664
|
+
startPolling = () => {
|
|
2665
|
+
this.sanityCheck();
|
|
2666
|
+
this.workers.forEach((worker) => {
|
|
2667
|
+
const options = this.workerManagerWorkerOptions(worker);
|
|
2668
|
+
const runner = new TaskRunner({
|
|
2669
|
+
worker,
|
|
2670
|
+
options,
|
|
2671
|
+
taskResource: this.client.taskResource,
|
|
2672
|
+
logger: this.logger,
|
|
2673
|
+
onError: this.errorHandler
|
|
2674
|
+
});
|
|
2675
|
+
runner.startPolling();
|
|
2676
|
+
this.workerRunners.set(worker.taskDefName, runner);
|
|
2677
|
+
});
|
|
2678
|
+
this.polling = true;
|
|
2679
|
+
};
|
|
2680
|
+
/**
|
|
2681
|
+
* Stops polling for tasks
|
|
2682
|
+
*/
|
|
2683
|
+
stopPolling = async () => {
|
|
2684
|
+
for (const [workerTaskDefName, runner] of this.workerRunners) {
|
|
2685
|
+
this.logger.debug(`Stopping taskDefName=${workerTaskDefName}`);
|
|
2686
|
+
await runner.stopPolling();
|
|
2687
|
+
this.workerRunners.delete(workerTaskDefName);
|
|
2688
|
+
}
|
|
2689
|
+
this.polling = false;
|
|
2690
|
+
};
|
|
2691
|
+
};
|
|
2692
|
+
|
|
2693
|
+
// src/core/types.ts
|
|
2694
|
+
var ConductorError = class extends Error {
|
|
2695
|
+
_trace;
|
|
2696
|
+
__proto__;
|
|
2697
|
+
constructor(message, innerError) {
|
|
2698
|
+
super(message);
|
|
2699
|
+
this._trace = innerError;
|
|
2700
|
+
const actualProto = new.target.prototype;
|
|
2701
|
+
if (Object.setPrototypeOf) {
|
|
2702
|
+
Object.setPrototypeOf(this, actualProto);
|
|
2657
2703
|
} else {
|
|
2658
2704
|
this.__proto__ = actualProto;
|
|
2659
2705
|
}
|
|
@@ -2669,10 +2715,20 @@ var tryCatchReThrow = (fn) => {
|
|
|
2669
2715
|
throw errorMapper(error);
|
|
2670
2716
|
}
|
|
2671
2717
|
};
|
|
2718
|
+
function reverseFind(array, predicate) {
|
|
2719
|
+
for (let i = array.length - 1; i >= 0; i--) {
|
|
2720
|
+
if (predicate(array[i], i, array)) {
|
|
2721
|
+
return array[i];
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
return void 0;
|
|
2725
|
+
}
|
|
2672
2726
|
|
|
2673
2727
|
// src/core/executor.ts
|
|
2674
2728
|
var RETRY_TIME_IN_MILLISECONDS = 1e4;
|
|
2729
|
+
var completedTaskMatchingType = (taskType) => (task) => task.status === "COMPLETED" && task.taskType === taskType;
|
|
2675
2730
|
var WorkflowExecutor = class {
|
|
2731
|
+
_client;
|
|
2676
2732
|
constructor(client) {
|
|
2677
2733
|
this._client = client;
|
|
2678
2734
|
}
|
|
@@ -2716,6 +2772,26 @@ var WorkflowExecutor = class {
|
|
|
2716
2772
|
startWorkflows(workflowsRequest) {
|
|
2717
2773
|
return tryCatchReThrow(() => workflowsRequest.map(this.startWorkflow));
|
|
2718
2774
|
}
|
|
2775
|
+
async goBackToTask(workflowInstanceId, taskFinderPredicate, rerunWorkflowRequestOverrides = {}) {
|
|
2776
|
+
const { tasks: executedTasks = [] } = await this.getExecution(
|
|
2777
|
+
workflowInstanceId
|
|
2778
|
+
);
|
|
2779
|
+
const maybePreviousTask = reverseFind(
|
|
2780
|
+
executedTasks,
|
|
2781
|
+
taskFinderPredicate
|
|
2782
|
+
);
|
|
2783
|
+
if (!maybePreviousTask) {
|
|
2784
|
+
throw new Error("Task not found");
|
|
2785
|
+
}
|
|
2786
|
+
await this.reRun(workflowInstanceId, {
|
|
2787
|
+
//taskInput: previousTask.inputData,
|
|
2788
|
+
...rerunWorkflowRequestOverrides,
|
|
2789
|
+
reRunFromTaskId: maybePreviousTask.taskId
|
|
2790
|
+
});
|
|
2791
|
+
}
|
|
2792
|
+
async goBackToFirstTaskMatchingType(workflowInstanceId, taskType) {
|
|
2793
|
+
return this.goBackToTask(workflowInstanceId, completedTaskMatchingType(taskType));
|
|
2794
|
+
}
|
|
2719
2795
|
/**
|
|
2720
2796
|
* Takes an workflowInstanceId and an includeTasks and an optional retry parameter returns the whole execution status.
|
|
2721
2797
|
* If includeTasks flag is provided. Details of tasks execution will be returned as well,
|
|
@@ -2760,6 +2836,22 @@ var WorkflowExecutor = class {
|
|
|
2760
2836
|
)
|
|
2761
2837
|
);
|
|
2762
2838
|
}
|
|
2839
|
+
/**
|
|
2840
|
+
* Returns a summary of the current workflow status.
|
|
2841
|
+
*
|
|
2842
|
+
* @param workflowInstanceId current running workflow
|
|
2843
|
+
* @param includeOutput flag to include output
|
|
2844
|
+
* @param includeVariables flag to include variable
|
|
2845
|
+
* @returns Promise<WorkflowStatus>
|
|
2846
|
+
*/
|
|
2847
|
+
getExecution(workflowInstanceId, includeTasks = true) {
|
|
2848
|
+
return tryCatchReThrow(
|
|
2849
|
+
() => this._client.workflowResource.getExecutionStatus(
|
|
2850
|
+
workflowInstanceId,
|
|
2851
|
+
includeTasks
|
|
2852
|
+
)
|
|
2853
|
+
);
|
|
2854
|
+
}
|
|
2763
2855
|
/**
|
|
2764
2856
|
* Pauses a running workflow
|
|
2765
2857
|
* @param workflowInstanceId current workflow execution
|
|
@@ -2929,11 +3021,25 @@ var WorkflowExecutor = class {
|
|
|
2929
3021
|
};
|
|
2930
3022
|
|
|
2931
3023
|
// src/core/human.ts
|
|
3024
|
+
var EMPTY_SEARCH = {
|
|
3025
|
+
size: 15,
|
|
3026
|
+
states: [],
|
|
3027
|
+
taskInputQuery: "",
|
|
3028
|
+
taskOutputQuery: "",
|
|
3029
|
+
definitionNames: [],
|
|
3030
|
+
taskRefNames: [],
|
|
3031
|
+
claimants: [],
|
|
3032
|
+
assignees: [],
|
|
3033
|
+
start: 0
|
|
3034
|
+
};
|
|
3035
|
+
var DEFAULT_POLL_INTERVAL2 = { pollInterval: 100, maxPollTimes: 20 };
|
|
2932
3036
|
var HumanExecutor = class {
|
|
3037
|
+
_client;
|
|
2933
3038
|
constructor(client) {
|
|
2934
3039
|
this._client = client;
|
|
2935
3040
|
}
|
|
2936
3041
|
/**
|
|
3042
|
+
* @deprecated use search instead
|
|
2937
3043
|
* Takes a set of filter parameters. return matches of human tasks for that set of parameters
|
|
2938
3044
|
* @param state
|
|
2939
3045
|
* @param assignee
|
|
@@ -2944,21 +3050,68 @@ var HumanExecutor = class {
|
|
|
2944
3050
|
* @param includeInputOutput
|
|
2945
3051
|
* @returns
|
|
2946
3052
|
*/
|
|
2947
|
-
async getTasksByFilter(state, assignee, assigneeType, claimedBy, taskName,
|
|
2948
|
-
const
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
3053
|
+
async getTasksByFilter(state, assignee, assigneeType, claimedBy, taskName, taskInputQuery, taskOutputQuery) {
|
|
3054
|
+
const [claimedUserType, claimedUser] = claimedBy?.split(":") ?? [];
|
|
3055
|
+
if (claimedUserType && !claimedUser) {
|
|
3056
|
+
throw new Error("claimedBy should be in the format of <userType>:<user>");
|
|
3057
|
+
}
|
|
3058
|
+
const response = await this.search({
|
|
3059
|
+
states: [state],
|
|
3060
|
+
assignees: assignee ? [{ userType: assigneeType, user: assignee }] : [],
|
|
3061
|
+
claimants: claimedBy ? [{ userType: claimedUserType, user: claimedUser }] : [],
|
|
3062
|
+
taskRefNames: taskName ? [taskName] : [],
|
|
3063
|
+
taskInputQuery,
|
|
3064
|
+
taskOutputQuery
|
|
3065
|
+
});
|
|
3066
|
+
return response;
|
|
3067
|
+
}
|
|
3068
|
+
/**
|
|
3069
|
+
* Takes a set of filter parameters. return matches of human tasks for that set of parameters
|
|
3070
|
+
* @param state
|
|
3071
|
+
* @param assignee
|
|
3072
|
+
* @param assigneeType
|
|
3073
|
+
* @param claimedBy
|
|
3074
|
+
* @param taskName
|
|
3075
|
+
* @param freeText
|
|
3076
|
+
* @param includeInputOutput
|
|
3077
|
+
* @returns Promise<HumanTaskEntry[]>
|
|
3078
|
+
*/
|
|
3079
|
+
async search(searchParams) {
|
|
3080
|
+
const search = { ...EMPTY_SEARCH, ...searchParams };
|
|
3081
|
+
const response = await tryCatchReThrow(
|
|
3082
|
+
() => this._client.humanTask.search(search)
|
|
2956
3083
|
);
|
|
2957
3084
|
if (response.results != void 0) {
|
|
2958
3085
|
return response.results;
|
|
2959
3086
|
}
|
|
2960
3087
|
return [];
|
|
2961
3088
|
}
|
|
3089
|
+
/**
|
|
3090
|
+
* Takes a set of filter parameters. An polling interval options. will poll until the task returns a result
|
|
3091
|
+
* @param state
|
|
3092
|
+
* @param assignee
|
|
3093
|
+
* @param assigneeType
|
|
3094
|
+
* @param claimedBy
|
|
3095
|
+
* @param taskName
|
|
3096
|
+
* @param freeText
|
|
3097
|
+
* @param includeInputOutput
|
|
3098
|
+
* @returns Promise<HumanTaskEntry[]>
|
|
3099
|
+
*/
|
|
3100
|
+
async pollSearch(searchParams, {
|
|
3101
|
+
pollInterval = 100,
|
|
3102
|
+
maxPollTimes = 20
|
|
3103
|
+
} = DEFAULT_POLL_INTERVAL2) {
|
|
3104
|
+
let pollCount = 0;
|
|
3105
|
+
while (pollCount < maxPollTimes) {
|
|
3106
|
+
const response = await this.search(searchParams);
|
|
3107
|
+
if (response.length > 0) {
|
|
3108
|
+
return response;
|
|
3109
|
+
}
|
|
3110
|
+
await new Promise((resolve3) => setTimeout(resolve3, pollInterval));
|
|
3111
|
+
pollCount++;
|
|
3112
|
+
}
|
|
3113
|
+
return [];
|
|
3114
|
+
}
|
|
2962
3115
|
/**
|
|
2963
3116
|
* Returns task for a given task id
|
|
2964
3117
|
* @param taskId
|
|
@@ -2974,11 +3127,9 @@ var HumanExecutor = class {
|
|
|
2974
3127
|
* @returns
|
|
2975
3128
|
*/
|
|
2976
3129
|
async claimTaskAsExternalUser(taskId, assignee) {
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
throw errorMapper(error);
|
|
2981
|
-
}
|
|
3130
|
+
return tryCatchReThrow(
|
|
3131
|
+
() => this._client.humanTask.assignAndClaim(taskId, assignee)
|
|
3132
|
+
);
|
|
2982
3133
|
}
|
|
2983
3134
|
/**
|
|
2984
3135
|
* Claim task as conductor user
|
|
@@ -2986,11 +3137,7 @@ var HumanExecutor = class {
|
|
|
2986
3137
|
* @returns
|
|
2987
3138
|
*/
|
|
2988
3139
|
async claimTaskAsConductorUser(taskId) {
|
|
2989
|
-
|
|
2990
|
-
await this._client.humanTask.claimTask(taskId);
|
|
2991
|
-
} catch (error) {
|
|
2992
|
-
throw errorMapper(error);
|
|
2993
|
-
}
|
|
3140
|
+
return tryCatchReThrow(() => this._client.humanTask.claimTask(taskId));
|
|
2994
3141
|
}
|
|
2995
3142
|
/**
|
|
2996
3143
|
* Claim task as conductor user
|
|
@@ -3006,15 +3153,24 @@ var HumanExecutor = class {
|
|
|
3006
3153
|
}
|
|
3007
3154
|
}
|
|
3008
3155
|
/**
|
|
3009
|
-
* Returns a HumanTaskTemplateEntry for a given
|
|
3156
|
+
* Returns a HumanTaskTemplateEntry for a given name and version
|
|
3010
3157
|
* @param templateId
|
|
3011
3158
|
* @returns
|
|
3012
3159
|
*/
|
|
3013
|
-
async
|
|
3160
|
+
async getTemplateByNameVersion(name, version) {
|
|
3014
3161
|
return tryCatchReThrow(
|
|
3015
|
-
() => this._client.humanTask.
|
|
3162
|
+
() => this._client.humanTask.getTemplateByNameAndVersion(name, version)
|
|
3016
3163
|
);
|
|
3017
3164
|
}
|
|
3165
|
+
/**
|
|
3166
|
+
* @deprecated use getTemplate instead. name will be used as id here with version 1
|
|
3167
|
+
* Returns a HumanTaskTemplateEntry for a given templateId
|
|
3168
|
+
* @param templateId
|
|
3169
|
+
* @returns
|
|
3170
|
+
*/
|
|
3171
|
+
async getTemplateById(templateNameVersionOne) {
|
|
3172
|
+
return this.getTemplateByNameVersion(templateNameVersionOne, 1);
|
|
3173
|
+
}
|
|
3018
3174
|
/**
|
|
3019
3175
|
* Takes a taskId and a partial body. will update with given body
|
|
3020
3176
|
* @param taskId
|
|
@@ -3523,105 +3679,73 @@ var workflow = (name, tasks) => ({
|
|
|
3523
3679
|
timeoutSeconds: 0
|
|
3524
3680
|
});
|
|
3525
3681
|
|
|
3526
|
-
// src/orkes/
|
|
3527
|
-
var
|
|
3528
|
-
var
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
try {
|
|
3534
|
-
const addresses = await resolver(host);
|
|
3535
|
-
if (addresses.length > 0)
|
|
3536
|
-
return addresses[0];
|
|
3537
|
-
} catch (e) {
|
|
3538
|
-
logger.error("Could not resolve host: " + host + " error: " + e);
|
|
3539
|
-
}
|
|
3540
|
-
return void 0;
|
|
3541
|
-
};
|
|
3542
|
-
|
|
3543
|
-
// src/orkes/request/fetchCatchDns/DnsCache.ts
|
|
3544
|
-
var DnsCacheResolver = class {
|
|
3545
|
-
constructor({ initialCache = /* @__PURE__ */ new Map() } = {}) {
|
|
3546
|
-
this._cache = /* @__PURE__ */ new Map();
|
|
3547
|
-
this._cache = initialCache;
|
|
3682
|
+
// src/orkes/BaseOrkesConductorClient.ts
|
|
3683
|
+
var defaultRequestHandler2 = (request3, config, options) => request3(config, options);
|
|
3684
|
+
var REFRESH_TOKEN_IN_MILLISECONDS = 30 * 60 * 1e3;
|
|
3685
|
+
var AuthConductorClient = class extends ConductorClient {
|
|
3686
|
+
intervalId;
|
|
3687
|
+
constructor(config, requestHandler = defaultRequestHandler2) {
|
|
3688
|
+
super(config, requestHandler);
|
|
3548
3689
|
}
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
if (ip != void 0) {
|
|
3556
|
-
this._cache.set(host, ip);
|
|
3690
|
+
/**
|
|
3691
|
+
* Stops the interval that refreshes the token
|
|
3692
|
+
*/
|
|
3693
|
+
stop() {
|
|
3694
|
+
if (this.intervalId != null) {
|
|
3695
|
+
clearInterval(this.intervalId);
|
|
3557
3696
|
}
|
|
3558
|
-
return ip;
|
|
3559
3697
|
}
|
|
3560
|
-
clearCache() {
|
|
3561
|
-
this._cache.clear();
|
|
3562
|
-
}
|
|
3563
|
-
removeCache(host) {
|
|
3564
|
-
this._cache.delete(host);
|
|
3565
|
-
}
|
|
3566
|
-
get cache() {
|
|
3567
|
-
return this._cache;
|
|
3568
|
-
}
|
|
3569
|
-
};
|
|
3570
|
-
|
|
3571
|
-
// src/orkes/request/fetchCatchDns/fetchCatchDns.ts
|
|
3572
|
-
var import_net = require("net");
|
|
3573
|
-
var isEmpty = (value) => {
|
|
3574
|
-
return value === void 0 || value.trim().length === 0;
|
|
3575
|
-
};
|
|
3576
|
-
var toMaybeUrl = (originalUrl, modifiedParams) => {
|
|
3577
|
-
const urlToHit = new URL(originalUrl.toString());
|
|
3578
|
-
urlToHit.host = isEmpty(modifiedParams.port) ? `${modifiedParams.host}:${modifiedParams.port}` : modifiedParams.host;
|
|
3579
|
-
return urlToHit;
|
|
3580
|
-
};
|
|
3581
|
-
var DEFAULT_OPTIONS2 = {
|
|
3582
|
-
dnsCache: new DnsCacheResolver(),
|
|
3583
|
-
headerFactory: (headers) => new Headers(headers || {})
|
|
3584
3698
|
};
|
|
3585
|
-
var
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3699
|
+
var baseOrkesConductorClient = (fetchFn, baseRequestHandler = defaultRequestHandler2) => {
|
|
3700
|
+
const requestTokenForKeySecret = (keyId, keySecret, tokenUrl) => fetchFn(tokenUrl, {
|
|
3701
|
+
headers: {
|
|
3702
|
+
"Content-Type": "application/json",
|
|
3703
|
+
Accept: "application/json"
|
|
3704
|
+
},
|
|
3705
|
+
body: JSON.stringify({ keyId, keySecret }),
|
|
3706
|
+
method: "POST"
|
|
3707
|
+
});
|
|
3708
|
+
return async (config, requestHandler = baseRequestHandler) => {
|
|
3709
|
+
if (config?.keySecret != null && config?.keyId != null) {
|
|
3710
|
+
const {
|
|
3711
|
+
serverUrl,
|
|
3712
|
+
keyId,
|
|
3713
|
+
keySecret,
|
|
3714
|
+
refreshTokenInterval = REFRESH_TOKEN_IN_MILLISECONDS
|
|
3715
|
+
} = config;
|
|
3716
|
+
const tokenUrl = `${serverUrl}/token`;
|
|
3717
|
+
const res = await requestTokenForKeySecret(keyId, keySecret, tokenUrl);
|
|
3718
|
+
const { token } = await res.json();
|
|
3719
|
+
const conductorClientInstance = new AuthConductorClient(
|
|
3720
|
+
{ ...config, TOKEN: token },
|
|
3721
|
+
requestHandler
|
|
3722
|
+
);
|
|
3723
|
+
if (token != null && refreshTokenInterval > 0) {
|
|
3724
|
+
const intervalId = setInterval(async () => {
|
|
3725
|
+
const res2 = await requestTokenForKeySecret(
|
|
3726
|
+
keyId,
|
|
3727
|
+
keySecret,
|
|
3728
|
+
tokenUrl
|
|
3729
|
+
);
|
|
3730
|
+
const { token: token2 } = await res2.json();
|
|
3731
|
+
conductorClientInstance.token = token2;
|
|
3732
|
+
}, refreshTokenInterval);
|
|
3733
|
+
conductorClientInstance.intervalId = intervalId;
|
|
3618
3734
|
}
|
|
3619
|
-
|
|
3735
|
+
return conductorClientInstance;
|
|
3736
|
+
} else {
|
|
3737
|
+
return new ConductorClient(config, requestHandler);
|
|
3620
3738
|
}
|
|
3621
3739
|
};
|
|
3622
|
-
return fetchWithDns;
|
|
3623
3740
|
};
|
|
3624
3741
|
|
|
3742
|
+
// src/orkes/OrkesConductorClient.ts
|
|
3743
|
+
var defaultRequestHandler3 = (request3, config, options) => request3(config, options);
|
|
3744
|
+
var orkesConductorClient = baseOrkesConductorClient(
|
|
3745
|
+
fetch,
|
|
3746
|
+
defaultRequestHandler3
|
|
3747
|
+
);
|
|
3748
|
+
|
|
3625
3749
|
// src/orkes/request/request.ts
|
|
3626
3750
|
var isDefined2 = (value) => {
|
|
3627
3751
|
return value !== void 0 && value !== null;
|
|
@@ -3857,91 +3981,104 @@ var request2 = (config, options, fetchFn = fetch) => {
|
|
|
3857
3981
|
});
|
|
3858
3982
|
};
|
|
3859
3983
|
|
|
3860
|
-
// src/orkes/
|
|
3861
|
-
var
|
|
3862
|
-
var
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3984
|
+
// src/orkes/request/fetchCatchDns/DnsResolver.ts
|
|
3985
|
+
var import_dns = require("dns");
|
|
3986
|
+
var DEFAULT_OPTIONS = {
|
|
3987
|
+
logger: noopLogger,
|
|
3988
|
+
resolver: import_dns.promises.resolve4
|
|
3989
|
+
};
|
|
3990
|
+
var dnsResolver = async (host, { resolver = import_dns.promises.resolve4, logger = console } = DEFAULT_OPTIONS) => {
|
|
3991
|
+
try {
|
|
3992
|
+
const addresses = await resolver(host);
|
|
3993
|
+
if (addresses.length > 0)
|
|
3994
|
+
return addresses[0];
|
|
3995
|
+
} catch (e) {
|
|
3996
|
+
logger.error("Could not resolve host: " + host + " error: " + e);
|
|
3866
3997
|
}
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3998
|
+
return void 0;
|
|
3999
|
+
};
|
|
4000
|
+
|
|
4001
|
+
// src/orkes/request/fetchCatchDns/DnsCache.ts
|
|
4002
|
+
var DnsCacheResolver = class {
|
|
4003
|
+
_cache = /* @__PURE__ */ new Map();
|
|
4004
|
+
constructor({ initialCache = /* @__PURE__ */ new Map() } = {}) {
|
|
4005
|
+
this._cache = initialCache;
|
|
4006
|
+
}
|
|
4007
|
+
async resolve(host) {
|
|
4008
|
+
const cachedIp = this._cache.get(host);
|
|
4009
|
+
if (cachedIp) {
|
|
4010
|
+
return cachedIp;
|
|
4011
|
+
}
|
|
4012
|
+
const ip = await dnsResolver(host);
|
|
4013
|
+
if (ip != void 0) {
|
|
4014
|
+
this._cache.set(host, ip);
|
|
3873
4015
|
}
|
|
4016
|
+
return ip;
|
|
4017
|
+
}
|
|
4018
|
+
clearCache() {
|
|
4019
|
+
this._cache.clear();
|
|
4020
|
+
}
|
|
4021
|
+
removeCache(host) {
|
|
4022
|
+
this._cache.delete(host);
|
|
4023
|
+
}
|
|
4024
|
+
get cache() {
|
|
4025
|
+
return this._cache;
|
|
3874
4026
|
}
|
|
3875
4027
|
};
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
}
|
|
3885
|
-
return
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
);
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
4028
|
+
|
|
4029
|
+
// src/orkes/request/fetchCatchDns/fetchCatchDns.ts
|
|
4030
|
+
var import_net = require("net");
|
|
4031
|
+
var isEmpty = (value) => {
|
|
4032
|
+
return value === void 0 || value.trim().length === 0;
|
|
4033
|
+
};
|
|
4034
|
+
var toMaybeUrl = (originalUrl, modifiedParams) => {
|
|
4035
|
+
const urlToHit = new URL(originalUrl.toString());
|
|
4036
|
+
urlToHit.host = isEmpty(modifiedParams.port) ? `${modifiedParams.host}:${modifiedParams.port}` : modifiedParams.host;
|
|
4037
|
+
return urlToHit;
|
|
4038
|
+
};
|
|
4039
|
+
var DEFAULT_OPTIONS2 = {
|
|
4040
|
+
dnsCache: new DnsCacheResolver(),
|
|
4041
|
+
headerFactory: (headers) => new Headers(headers || {})
|
|
4042
|
+
};
|
|
4043
|
+
var fetchCatchDns = (fetch2, {
|
|
4044
|
+
dnsCache = new DnsCacheResolver(),
|
|
4045
|
+
headerFactory = (headers) => new Headers(headers || {})
|
|
4046
|
+
} = DEFAULT_OPTIONS2) => {
|
|
4047
|
+
const fetchWithDns = async (input, options) => {
|
|
4048
|
+
const parsedUrl = new URL(input.toString());
|
|
4049
|
+
const { hostname, host, port } = parsedUrl;
|
|
4050
|
+
if ((0, import_net.isIP)(hostname)) {
|
|
4051
|
+
return await fetch2(input, options);
|
|
4052
|
+
}
|
|
4053
|
+
const maybeTargetIp = await dnsCache.resolve(hostname);
|
|
4054
|
+
if (isEmpty(maybeTargetIp)) {
|
|
4055
|
+
return await fetch2(input, options);
|
|
4056
|
+
}
|
|
4057
|
+
const target = toMaybeUrl(input, {
|
|
4058
|
+
...parsedUrl,
|
|
4059
|
+
host: maybeTargetIp,
|
|
4060
|
+
port
|
|
4061
|
+
});
|
|
4062
|
+
const headersOverride = headerFactory(options?.headers ?? {});
|
|
4063
|
+
if (!headersOverride.has("Host")) {
|
|
4064
|
+
headersOverride.set("Host", host);
|
|
4065
|
+
}
|
|
4066
|
+
const optionsOverride = {
|
|
4067
|
+
...options,
|
|
4068
|
+
headers: headersOverride
|
|
4069
|
+
};
|
|
4070
|
+
try {
|
|
4071
|
+
const res = await fetch2(target.toString(), optionsOverride);
|
|
4072
|
+
return res;
|
|
4073
|
+
} catch (e) {
|
|
4074
|
+
if (e && e?.code === "ETIMEDOUT") {
|
|
4075
|
+
dnsCache.removeCache(hostname);
|
|
3911
4076
|
}
|
|
3912
|
-
|
|
3913
|
-
} else {
|
|
3914
|
-
return new ConductorClient(config, requestHandler);
|
|
4077
|
+
throw e;
|
|
3915
4078
|
}
|
|
3916
4079
|
};
|
|
4080
|
+
return fetchWithDns;
|
|
3917
4081
|
};
|
|
3918
|
-
|
|
3919
|
-
// src/orkes/OrkesConductorClient.ts
|
|
3920
|
-
var import_node_fetch = __toESM(require("node-fetch"));
|
|
3921
|
-
var import_http = __toESM(require("http"));
|
|
3922
|
-
var import_https = __toESM(require("https"));
|
|
3923
|
-
var httpAgent = new import_http.default.Agent({ keepAlive: true });
|
|
3924
|
-
var httpsAgent = new import_https.default.Agent({ keepAlive: true });
|
|
3925
|
-
var agent = (_parsedURL) => _parsedURL.protocol == "http:" ? httpAgent : httpsAgent;
|
|
3926
|
-
var nodeFetchWrapper = async (input, options = {}) => {
|
|
3927
|
-
const res = await (0, import_node_fetch.default)(input.toString(), {
|
|
3928
|
-
...options,
|
|
3929
|
-
agent
|
|
3930
|
-
});
|
|
3931
|
-
return res;
|
|
3932
|
-
};
|
|
3933
|
-
var fetchCache = fetchCatchDns(
|
|
3934
|
-
nodeFetchWrapper,
|
|
3935
|
-
{
|
|
3936
|
-
//@ts-ignore
|
|
3937
|
-
headerFactory: (headers) => new import_node_fetch.Headers(headers || {})
|
|
3938
|
-
}
|
|
3939
|
-
);
|
|
3940
|
-
var defaultRequestHandler3 = (__request, config, options) => request2(config, options, fetchCache);
|
|
3941
|
-
var orkesConductorClient = baseOrkesConductorClient(
|
|
3942
|
-
fetchCache,
|
|
3943
|
-
defaultRequestHandler3
|
|
3944
|
-
);
|
|
3945
4082
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3946
4083
|
0 && (module.exports = {
|
|
3947
4084
|
ApiError,
|
|
@@ -3967,6 +4104,7 @@ var orkesConductorClient = baseOrkesConductorClient(
|
|
|
3967
4104
|
WorkflowExecutor,
|
|
3968
4105
|
WorkflowResourceService,
|
|
3969
4106
|
baseOrkesConductorClient,
|
|
4107
|
+
completedTaskMatchingType,
|
|
3970
4108
|
conductorEventTask,
|
|
3971
4109
|
doWhileTask,
|
|
3972
4110
|
dynamicForkTask,
|