@io-orkes/conductor-javascript 2.0.0-rc1 → 2.0.0-rc3

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/dist/index.js CHANGED
@@ -38,7 +38,6 @@ __export(conductor_javascript_exports, {
38
38
  ConductorClient: () => ConductorClient,
39
39
  ConductorError: () => ConductorError,
40
40
  DefaultLogger: () => DefaultLogger,
41
- DnsCacheResolver: () => DnsCacheResolver,
42
41
  EventResourceService: () => EventResourceService,
43
42
  HealthCheckResourceService: () => HealthCheckResourceService,
44
43
  HumanExecutor: () => HumanExecutor,
@@ -58,7 +57,6 @@ __export(conductor_javascript_exports, {
58
57
  doWhileTask: () => doWhileTask,
59
58
  dynamicForkTask: () => dynamicForkTask,
60
59
  eventTask: () => eventTask,
61
- fetchCatchDns: () => fetchCatchDns,
62
60
  forkTask: () => forkTask,
63
61
  forkTaskJoin: () => forkTaskJoin,
64
62
  generate: () => generate,
@@ -93,7 +91,6 @@ __export(conductor_javascript_exports, {
93
91
  switchTask: () => switchTask,
94
92
  taskGenMapper: () => taskGenMapper,
95
93
  terminateTask: () => terminateTask,
96
- toMaybeUrl: () => toMaybeUrl,
97
94
  waitTaskDuration: () => waitTaskDuration,
98
95
  waitTaskUntil: () => waitTaskUntil,
99
96
  workflow: () => workflow
@@ -107,16 +104,9 @@ var LOG_LEVELS = {
107
104
  ERROR: 60
108
105
  };
109
106
  var DefaultLogger = class {
107
+ tags;
108
+ level;
110
109
  constructor(config = {}) {
111
- this.info = (...args) => {
112
- this.log("INFO", ...args);
113
- };
114
- this.debug = (...args) => {
115
- this.log("DEBUG", ...args);
116
- };
117
- this.error = (...args) => {
118
- this.log("ERROR", ...args);
119
- };
120
110
  const { level, tags = [] } = config;
121
111
  this.tags = tags;
122
112
  if (level && level in LOG_LEVELS) {
@@ -138,6 +128,15 @@ var DefaultLogger = class {
138
128
  console.log(name, ...this.tags, ...args);
139
129
  }
140
130
  }
131
+ info = (...args) => {
132
+ this.log("INFO", ...args);
133
+ };
134
+ debug = (...args) => {
135
+ this.log("DEBUG", ...args);
136
+ };
137
+ error = (...args) => {
138
+ this.log("ERROR", ...args);
139
+ };
141
140
  };
142
141
  var noopLogger = {
143
142
  //eslint-disable-next-line
@@ -1588,6 +1587,11 @@ var WorkflowResourceService = class {
1588
1587
 
1589
1588
  // src/common/open-api/core/ApiError.ts
1590
1589
  var ApiError = class extends Error {
1590
+ url;
1591
+ status;
1592
+ statusText;
1593
+ body;
1594
+ request;
1591
1595
  constructor(request3, response, message) {
1592
1596
  super(message);
1593
1597
  this.name = "ApiError";
@@ -1610,9 +1614,14 @@ var CancelError = class extends Error {
1610
1614
  }
1611
1615
  };
1612
1616
  var CancelablePromise = class {
1613
- static {
1614
- Symbol.toStringTag;
1615
- }
1617
+ [Symbol.toStringTag];
1618
+ _isResolved;
1619
+ _isRejected;
1620
+ _isCancelled;
1621
+ _cancelHandlers;
1622
+ _promise;
1623
+ _resolve;
1624
+ _reject;
1616
1625
  constructor(executor) {
1617
1626
  this._isResolved = false;
1618
1627
  this._isRejected = false;
@@ -2249,6 +2258,18 @@ var HumanTaskResourceService = class {
2249
2258
  // src/common/open-api/ConductorClient.ts
2250
2259
  var defaultRequestHandler = (request3, config, options) => request3(config, options);
2251
2260
  var ConductorClient = class {
2261
+ eventResource;
2262
+ healthCheckResource;
2263
+ metadataResource;
2264
+ schedulerResource;
2265
+ taskResource;
2266
+ tokenResource;
2267
+ workflowBulkResource;
2268
+ workflowResource;
2269
+ humanTask;
2270
+ humanTaskResource;
2271
+ request;
2272
+ token;
2252
2273
  constructor(config, requestHandler = defaultRequestHandler) {
2253
2274
  const resolvedConfig = {
2254
2275
  BASE: config?.serverUrl ?? "http://localhost:8080",
@@ -2302,75 +2323,21 @@ var DEFAULT_BATCH_POLLING_TIMEOUT = 100;
2302
2323
 
2303
2324
  // src/task/Poller.ts
2304
2325
  var Poller = class {
2326
+ timeoutHandler;
2327
+ pollFunction;
2328
+ performWorkFunction = async () => {
2329
+ };
2330
+ polling = false;
2331
+ _tasksInProcess = 0;
2332
+ _counterAtO = 0;
2333
+ _pollerId = "";
2334
+ options = {
2335
+ pollInterval: DEFAULT_POLL_INTERVAL,
2336
+ concurrency: DEFAULT_CONCURRENCY,
2337
+ warnAtO: DEFAULT_WARN_AT_O
2338
+ };
2339
+ logger = noopLogger;
2305
2340
  constructor(pollerId, pollFunction, performWorkFunction, pollerOptions, logger) {
2306
- this.performWorkFunction = async () => {
2307
- };
2308
- this.polling = false;
2309
- this._tasksInProcess = 0;
2310
- this._counterAtO = 0;
2311
- this._pollerId = "";
2312
- this.options = {
2313
- pollInterval: DEFAULT_POLL_INTERVAL,
2314
- concurrency: DEFAULT_CONCURRENCY,
2315
- warnAtO: DEFAULT_WARN_AT_O
2316
- };
2317
- this.logger = noopLogger;
2318
- /**
2319
- * Starts polling for work
2320
- */
2321
- this.startPolling = () => {
2322
- if (this.polling) {
2323
- throw new Error("Runner is already started");
2324
- }
2325
- this._tasksInProcess = 0;
2326
- this.polling = true;
2327
- this.poll();
2328
- };
2329
- /**
2330
- * Stops Polling for work
2331
- */
2332
- this.stopPolling = async () => {
2333
- this.polling = false;
2334
- clearTimeout(this.timeoutHandler);
2335
- };
2336
- this.performWork = async (work) => {
2337
- await this.performWorkFunction(work);
2338
- this._tasksInProcess--;
2339
- };
2340
- this.poll = async () => {
2341
- while (this.isPolling) {
2342
- try {
2343
- const count = Math.max(
2344
- 0,
2345
- this.options.concurrency - this._tasksInProcess
2346
- );
2347
- if (count === 0) {
2348
- this.logger.debug(
2349
- "Max in process reached, Will skip polling for " + this._pollerId
2350
- );
2351
- this._counterAtO++;
2352
- if (this._counterAtO > (this.options.warnAtO ?? 100)) {
2353
- this.logger.info(
2354
- `Not polling anything because in process tasks is maxed as concurrency level. ${this._pollerId}`
2355
- );
2356
- }
2357
- } else {
2358
- this._counterAtO = 0;
2359
- const tasksResult = await this.pollFunction(count);
2360
- this._tasksInProcess = this._tasksInProcess + (tasksResult ?? []).length;
2361
- tasksResult.forEach(this.performWork);
2362
- }
2363
- } catch (e) {
2364
- this.logger.error(`Error polling for tasks: ${e.message}`, e);
2365
- }
2366
- await new Promise(
2367
- (r) => this.isPolling ? this.timeoutHandler = setTimeout(
2368
- () => r(true),
2369
- this.options.pollInterval
2370
- ) : r(true)
2371
- );
2372
- }
2373
- };
2374
2341
  this._pollerId = pollerId;
2375
2342
  this.pollFunction = pollFunction;
2376
2343
  this.performWorkFunction = performWorkFunction;
@@ -2383,10 +2350,66 @@ var Poller = class {
2383
2350
  get tasksInProcess() {
2384
2351
  return this._tasksInProcess;
2385
2352
  }
2353
+ /**
2354
+ * Starts polling for work
2355
+ */
2356
+ startPolling = () => {
2357
+ if (this.polling) {
2358
+ throw new Error("Runner is already started");
2359
+ }
2360
+ this._tasksInProcess = 0;
2361
+ this.polling = true;
2362
+ this.poll();
2363
+ };
2364
+ /**
2365
+ * Stops Polling for work
2366
+ */
2367
+ stopPolling = async () => {
2368
+ this.polling = false;
2369
+ clearTimeout(this.timeoutHandler);
2370
+ };
2371
+ performWork = async (work) => {
2372
+ await this.performWorkFunction(work);
2373
+ this._tasksInProcess--;
2374
+ };
2386
2375
  updateOptions(options) {
2387
2376
  const newOptions = { ...this.options, ...options };
2388
2377
  this.options = newOptions;
2389
2378
  }
2379
+ poll = async () => {
2380
+ while (this.isPolling) {
2381
+ try {
2382
+ const count = Math.max(
2383
+ 0,
2384
+ this.options.concurrency - this._tasksInProcess
2385
+ );
2386
+ if (count === 0) {
2387
+ this.logger.debug(
2388
+ "Max in process reached, Will skip polling for " + this._pollerId
2389
+ );
2390
+ this._counterAtO++;
2391
+ if (this._counterAtO > (this.options.warnAtO ?? 100)) {
2392
+ this.logger.info(
2393
+ `Not polling anything because in process tasks is maxed as concurrency level. ${this._pollerId}`
2394
+ );
2395
+ }
2396
+ } else {
2397
+ this._counterAtO = 0;
2398
+ const tasksResult = await this.pollFunction(count);
2399
+ this._tasksInProcess = this._tasksInProcess + (tasksResult ?? []).length;
2400
+ tasksResult.forEach(this.performWork);
2401
+ }
2402
+ } catch (e) {
2403
+ this.logger.error(`Error polling for tasks: ${e.message}`, e);
2404
+ }
2405
+ await new Promise(
2406
+ (r) => this.isPolling ? this.timeoutHandler = setTimeout(
2407
+ () => r(true),
2408
+ this.options.pollInterval
2409
+ ) : r(true)
2410
+ );
2411
+ }
2412
+ };
2390
2413
  };
2391
2414
 
2392
2415
  // src/task/helpers.ts
@@ -2411,6 +2434,12 @@ var defaultRunnerOptions = {
2411
2434
  batchPollingTimeout: DEFAULT_BATCH_POLLING_TIMEOUT
2412
2435
  };
2413
2436
  var TaskRunner = class {
2437
+ taskResource;
2438
+ worker;
2439
+ logger;
2440
+ options;
2441
+ errorHandler;
2442
+ poller;
2414
2443
  constructor({
2415
2444
  worker,
2416
2445
  taskResource,
@@ -2418,91 +2447,6 @@ var TaskRunner = class {
2418
2447
  logger = noopLogger,
2419
2448
  onError: errorHandler = noopErrorHandler
2420
2449
  }) {
2421
- /**
2422
- * Starts polling for work
2423
- */
2424
- this.startPolling = () => {
2425
- this.poller.startPolling();
2426
- this.logger.info(
2427
- `TaskWorker ${this.worker.taskDefName} initialized with concurrency of ${this.poller.options.concurrency} and poll interval of ${this.poller.options.pollInterval}`
2428
- );
2429
- };
2430
- /**
2431
- * Stops Polling for work
2432
- */
2433
- this.stopPolling = async () => {
2434
- await this.poller.stopPolling();
2435
- };
2436
- this.batchPoll = async (count) => {
2437
- const { workerID } = this.options;
2438
- const tasks = await this.taskResource.batchPoll(
2439
- this.worker.taskDefName,
2440
- workerID,
2441
- this.worker.domain ?? this.options.domain,
2442
- count,
2443
- this.options.batchPollingTimeout ?? 100
2444
- // default batch poll defined in the method
2445
- );
2446
- return tasks;
2447
- };
2448
- this.updateTaskWithRetry = async (task, taskResult) => {
2449
- const { workerID } = this.options;
2450
- let retryCount = 0;
2451
- while (retryCount < MAX_RETRIES) {
2452
- try {
2453
- await this.taskResource.updateTask1({
2454
- ...taskResult,
2455
- workerId: workerID
2456
- });
2457
- return;
2458
- } catch (error) {
2459
- this.errorHandler(error, task);
2460
- this.logger.error(
2461
- `Error updating task ${taskResult.taskId} on retry ${retryCount}`,
2462
- error
2463
- );
2464
- retryCount++;
2465
- await new Promise((r) => setTimeout(() => r(true), retryCount * 10));
2466
- }
2467
- }
2468
- this.logger.error(
2469
- `Unable to update task ${taskResult.taskId} after ${retryCount} retries`
2470
- );
2471
- };
2472
- this.executeTask = async (task) => {
2473
- try {
2474
- const result = await this.worker.execute(task);
2475
- await this.updateTaskWithRetry(task, {
2476
- ...result,
2477
- workflowInstanceId: task.workflowInstanceId,
2478
- taskId: task.taskId
2479
- });
2480
- this.logger.debug(`Task has executed successfully ${task.taskId}`);
2481
- } catch (error) {
2482
- await this.updateTaskWithRetry(task, {
2483
- workflowInstanceId: task.workflowInstanceId,
2484
- taskId: task.taskId,
2485
- reasonForIncompletion: error?.message ?? DEFAULT_ERROR_MESSAGE,
2486
- status: "FAILED",
2487
- outputData: {}
2488
- });
2489
- this.errorHandler(error, task);
2490
- this.logger.error(`Error executing ${task.taskId}`, error);
2491
- }
2492
- };
2493
- this.handleUnknownError = (unknownError) => {
2494
- let message = "";
2495
- let stack = "";
2496
- if (unknownError.stack) {
2497
- stack = unknownError.stack;
2498
- }
2499
- if (unknownError.message) {
2500
- message = unknownError.message;
2501
- }
2502
- this.logger.error(
2503
- `Error for ${this.worker.taskDefName}: error: ${message}, stack: ${stack}`
2504
- );
2505
- };
2506
2450
  this.taskResource = taskResource;
2507
2451
  this.logger = logger;
2508
2452
  this.worker = worker;
@@ -2522,6 +2466,21 @@ var TaskRunner = class {
2522
2466
  get isPolling() {
2523
2467
  return this.poller.isPolling;
2524
2468
  }
2469
+ /**
2470
+ * Starts polling for work
2471
+ */
2472
+ startPolling = () => {
2473
+ this.poller.startPolling();
2474
+ this.logger.info(
2475
+ `TaskWorker ${this.worker.taskDefName} initialized with concurrency of ${this.poller.options.concurrency} and poll interval of ${this.poller.options.pollInterval}`
2476
+ );
2477
+ };
2478
+ /**
2479
+ * Stops Polling for work
2480
+ */
2481
+ stopPolling = async () => {
2482
+ await this.poller.stopPolling();
2483
+ };
2525
2484
  updateOptions(options) {
2526
2485
  const newOptions = { ...this.options, ...options };
2527
2486
  const isOptionsUpdated = !optionEquals(this.options, newOptions);
@@ -2539,6 +2498,76 @@ var TaskRunner = class {
2539
2498
  get getOptions() {
2540
2499
  return this.options;
2541
2500
  }
2501
+ batchPoll = async (count) => {
2502
+ const { workerID } = this.options;
2503
+ const tasks = await this.taskResource.batchPoll(
2504
+ this.worker.taskDefName,
2505
+ workerID,
2506
+ this.worker.domain ?? this.options.domain,
2507
+ count,
2508
+ this.options.batchPollingTimeout ?? 100
2509
+ // default batch poll defined in the method
2510
+ );
2511
+ return tasks;
2512
+ };
2513
+ updateTaskWithRetry = async (task, taskResult) => {
2514
+ const { workerID } = this.options;
2515
+ let retryCount = 0;
2516
+ while (retryCount < MAX_RETRIES) {
2517
+ try {
2518
+ await this.taskResource.updateTask1({
2519
+ ...taskResult,
2520
+ workerId: workerID
2521
+ });
2522
+ return;
2523
+ } catch (error) {
2524
+ this.errorHandler(error, task);
2525
+ this.logger.error(
2526
+ `Error updating task ${taskResult.taskId} on retry ${retryCount}`,
2527
+ error
2528
+ );
2529
+ retryCount++;
2530
+ await new Promise((r) => setTimeout(() => r(true), retryCount * 10));
2531
+ }
2532
+ }
2533
+ this.logger.error(
2534
+ `Unable to update task ${taskResult.taskId} after ${retryCount} retries`
2535
+ );
2536
+ };
2537
+ executeTask = async (task) => {
2538
+ try {
2539
+ const result = await this.worker.execute(task);
2540
+ await this.updateTaskWithRetry(task, {
2541
+ ...result,
2542
+ workflowInstanceId: task.workflowInstanceId,
2543
+ taskId: task.taskId
2544
+ });
2545
+ this.logger.debug(`Task has executed successfully ${task.taskId}`);
2546
+ } catch (error) {
2547
+ await this.updateTaskWithRetry(task, {
2548
+ workflowInstanceId: task.workflowInstanceId,
2549
+ taskId: task.taskId,
2550
+ reasonForIncompletion: error?.message ?? DEFAULT_ERROR_MESSAGE,
2551
+ status: "FAILED",
2552
+ outputData: {}
2553
+ });
2554
+ this.errorHandler(error, task);
2555
+ this.logger.error(`Error executing ${task.taskId}`, error);
2556
+ }
2557
+ };
2558
+ handleUnknownError = (unknownError) => {
2559
+ let message = "";
2560
+ let stack = "";
2561
+ if (unknownError.stack) {
2562
+ stack = unknownError.stack;
2563
+ }
2564
+ if (unknownError.message) {
2565
+ message = unknownError.message;
2566
+ }
2567
+ this.logger.error(
2568
+ `Error for ${this.worker.taskDefName}: error: ${message}, stack: ${stack}`
2569
+ );
2570
+ };
2542
2571
  };
2543
2572
 
2544
2573
  // src/task/TaskManager.ts
@@ -2554,84 +2583,14 @@ function workerId(options) {
2554
2583
  return options.workerID ?? import_os.default.hostname();
2555
2584
  }
2556
2585
  var TaskManager = class {
2586
+ workerRunners = /* @__PURE__ */ new Map();
2587
+ client;
2588
+ logger;
2589
+ errorHandler;
2590
+ workers;
2591
+ options;
2592
+ polling = false;
2557
2593
  constructor(client, workers, config = {}) {
2558
- this.workerRunners = /* @__PURE__ */ new Map();
2559
- this.polling = false;
2560
- this.workerManagerWorkerOptions = (worker) => {
2561
- return {
2562
- ...this.options,
2563
- concurrency: worker.concurrency ?? this.options.concurrency,
2564
- pollInterval: worker.pollInterval ?? this.options.pollInterval,
2565
- domain: worker.domain ?? this.options.domain
2566
- };
2567
- };
2568
- this.updatePollingOptionForWorker = (workerTaskDefName, options) => {
2569
- const maybeRunner = this.workerRunners.get(workerTaskDefName);
2570
- if (maybeRunner != null) {
2571
- maybeRunner.updateOptions(options);
2572
- } else {
2573
- this.logger.info(
2574
- `No runner found for worker with taskDefName: ${workerTaskDefName}`
2575
- );
2576
- }
2577
- };
2578
- /**
2579
- * new options will get merged to existing options
2580
- * @param options new options to update polling options
2581
- */
2582
- this.updatePollingOptions = (options) => {
2583
- this.workers.forEach((worker) => {
2584
- const newOptions = {
2585
- ...this.workerManagerWorkerOptions(worker),
2586
- ...options
2587
- };
2588
- this.updatePollingOptionForWorker(worker.taskDefName, newOptions);
2589
- });
2590
- this.options.concurrency = options.concurrency ?? this.options.concurrency;
2591
- this.options.pollInterval = options.pollInterval ?? this.options.pollInterval;
2592
- };
2593
- this.sanityCheck = () => {
2594
- if (this.workers.length === 0) {
2595
- throw new Error("No workers supplied to TaskManager");
2596
- }
2597
- const workerIDs = /* @__PURE__ */ new Set();
2598
- for (const item of this.workers) {
2599
- if (workerIDs.has(item.taskDefName)) {
2600
- throw new Error(`Duplicate worker taskDefName: ${item.taskDefName}`);
2601
- }
2602
- workerIDs.add(item.taskDefName);
2603
- }
2604
- };
2605
- /**
2606
- * Start polling for tasks
2607
- */
2608
- this.startPolling = () => {
2609
- this.sanityCheck();
2610
- this.workers.forEach((worker) => {
2611
- const options = this.workerManagerWorkerOptions(worker);
2612
- const runner = new TaskRunner({
2613
- worker,
2614
- options,
2615
- taskResource: this.client.taskResource,
2616
- logger: this.logger,
2617
- onError: this.errorHandler
2618
- });
2619
- runner.startPolling();
2620
- this.workerRunners.set(worker.taskDefName, runner);
2621
- });
2622
- this.polling = true;
2623
- };
2624
- /**
2625
- * Stops polling for tasks
2626
- */
2627
- this.stopPolling = async () => {
2628
- for (const [workerTaskDefName, runner] of this.workerRunners) {
2629
- this.logger.debug(`Stopping taskDefName=${workerTaskDefName}`);
2630
- await runner.stopPolling();
2631
- this.workerRunners.delete(workerTaskDefName);
2632
- }
2633
- this.polling = false;
2634
- };
2635
2594
  if (!workers) {
2636
2595
  throw new Error(
2637
2596
  "No workers supplied to TaskManager. Please pass an array of workers."
@@ -2648,13 +2607,90 @@ var TaskManager = class {
2648
2607
  workerID: workerId(providedOptions)
2649
2608
  };
2650
2609
  }
2610
+ workerManagerWorkerOptions = (worker) => {
2611
+ return {
2612
+ ...this.options,
2613
+ concurrency: worker.concurrency ?? this.options.concurrency,
2614
+ pollInterval: worker.pollInterval ?? this.options.pollInterval,
2615
+ domain: worker.domain ?? this.options.domain
2616
+ };
2617
+ };
2651
2618
  get isPolling() {
2652
2619
  return this.polling;
2653
2620
  }
2621
+ updatePollingOptionForWorker = (workerTaskDefName, options) => {
2622
+ const maybeRunner = this.workerRunners.get(workerTaskDefName);
2623
+ if (maybeRunner != null) {
2624
+ maybeRunner.updateOptions(options);
2625
+ } else {
2626
+ this.logger.info(
2627
+ `No runner found for worker with taskDefName: ${workerTaskDefName}`
2628
+ );
2629
+ }
2630
+ };
2631
+ /**
2632
+ * new options will get merged to existing options
2633
+ * @param options new options to update polling options
2634
+ */
2635
+ updatePollingOptions = (options) => {
2636
+ this.workers.forEach((worker) => {
2637
+ const newOptions = {
2638
+ ...this.workerManagerWorkerOptions(worker),
2639
+ ...options
2640
+ };
2641
+ this.updatePollingOptionForWorker(worker.taskDefName, newOptions);
2642
+ });
2643
+ this.options.concurrency = options.concurrency ?? this.options.concurrency;
2644
+ this.options.pollInterval = options.pollInterval ?? this.options.pollInterval;
2645
+ };
2646
+ sanityCheck = () => {
2647
+ if (this.workers.length === 0) {
2648
+ throw new Error("No workers supplied to TaskManager");
2649
+ }
2650
+ const workerIDs = /* @__PURE__ */ new Set();
2651
+ for (const item of this.workers) {
2652
+ if (workerIDs.has(item.taskDefName)) {
2653
+ throw new Error(`Duplicate worker taskDefName: ${item.taskDefName}`);
2654
+ }
2655
+ workerIDs.add(item.taskDefName);
2656
+ }
2657
+ };
2658
+ /**
2659
+ * Start polling for tasks
2660
+ */
2661
+ startPolling = () => {
2662
+ this.sanityCheck();
2663
+ this.workers.forEach((worker) => {
2664
+ const options = this.workerManagerWorkerOptions(worker);
2665
+ const runner = new TaskRunner({
2666
+ worker,
2667
+ options,
2668
+ taskResource: this.client.taskResource,
2669
+ logger: this.logger,
2670
+ onError: this.errorHandler
2671
+ });
2672
+ runner.startPolling();
2673
+ this.workerRunners.set(worker.taskDefName, runner);
2674
+ });
2675
+ this.polling = true;
2676
+ };
2677
+ /**
2678
+ * Stops polling for tasks
2679
+ */
2680
+ stopPolling = async () => {
2681
+ for (const [workerTaskDefName, runner] of this.workerRunners) {
2682
+ this.logger.debug(`Stopping taskDefName=${workerTaskDefName}`);
2683
+ await runner.stopPolling();
2684
+ this.workerRunners.delete(workerTaskDefName);
2685
+ }
2686
+ this.polling = false;
2687
+ };
2654
2688
  };
2655
2689
 
2656
2690
  // src/core/types.ts
2657
2691
  var ConductorError = class extends Error {
2692
+ _trace;
2693
+ __proto__;
2658
2694
  constructor(message, innerError) {
2659
2695
  super(message);
2660
2696
  this._trace = innerError;
@@ -2689,6 +2725,7 @@ function reverseFind(array, predicate) {
2689
2725
  var RETRY_TIME_IN_MILLISECONDS = 1e4;
2690
2726
  var completedTaskMatchingType = (taskType) => (task) => task.status === "COMPLETED" && task.taskType === taskType;
2691
2727
  var WorkflowExecutor = class {
2728
+ _client;
2692
2729
  constructor(client) {
2693
2730
  this._client = client;
2694
2731
  }
@@ -2994,6 +3031,7 @@ var EMPTY_SEARCH = {
2994
3031
  };
2995
3032
  var DEFAULT_POLL_INTERVAL2 = { pollInterval: 100, maxPollTimes: 20 };
2996
3033
  var HumanExecutor = class {
3034
+ _client;
2997
3035
  constructor(client) {
2998
3036
  this._client = client;
2999
3037
  }
@@ -3638,105 +3676,73 @@ var workflow = (name, tasks) => ({
3638
3676
  timeoutSeconds: 0
3639
3677
  });
3640
3678
 
3641
- // src/orkes/request/fetchCatchDns/DnsResolver.ts
3642
- var import_dns = require("dns");
3643
- var DEFAULT_OPTIONS = {
3644
- logger: noopLogger,
3645
- resolver: import_dns.promises.resolve4
3646
- };
3647
- var dnsResolver = async (host, { resolver = import_dns.promises.resolve4, logger = console } = DEFAULT_OPTIONS) => {
3648
- try {
3649
- const addresses = await resolver(host);
3650
- if (addresses.length > 0)
3651
- return addresses[0];
3652
- } catch (e) {
3653
- logger.error("Could not resolve host: " + host + " error: " + e);
3679
+ // src/orkes/BaseOrkesConductorClient.ts
3680
+ var defaultRequestHandler2 = (request3, config, options) => request3(config, options);
3681
+ var REFRESH_TOKEN_IN_MILLISECONDS = 30 * 60 * 1e3;
3682
+ var AuthConductorClient = class extends ConductorClient {
3683
+ intervalId;
3684
+ constructor(config, requestHandler = defaultRequestHandler2) {
3685
+ super(config, requestHandler);
3654
3686
  }
3655
- return void 0;
3656
- };
3657
-
3658
- // src/orkes/request/fetchCatchDns/DnsCache.ts
3659
- var DnsCacheResolver = class {
3660
- constructor({ initialCache = /* @__PURE__ */ new Map() } = {}) {
3661
- this._cache = /* @__PURE__ */ new Map();
3662
- this._cache = initialCache;
3663
- }
3664
- async resolve(host) {
3665
- const cachedIp = this._cache.get(host);
3666
- if (cachedIp) {
3667
- return cachedIp;
3668
- }
3669
- const ip = await dnsResolver(host);
3670
- if (ip != void 0) {
3671
- this._cache.set(host, ip);
3687
+ /**
3688
+ * Stops the interval that refreshes the token
3689
+ */
3690
+ stop() {
3691
+ if (this.intervalId != null) {
3692
+ clearInterval(this.intervalId);
3672
3693
  }
3673
- return ip;
3674
3694
  }
3675
- clearCache() {
3676
- this._cache.clear();
3677
- }
3678
- removeCache(host) {
3679
- this._cache.delete(host);
3680
- }
3681
- get cache() {
3682
- return this._cache;
3683
- }
3684
- };
3685
-
3686
- // src/orkes/request/fetchCatchDns/fetchCatchDns.ts
3687
- var import_net = require("net");
3688
- var isEmpty = (value) => {
3689
- return value === void 0 || value.trim().length === 0;
3690
3695
  };
3691
- var toMaybeUrl = (originalUrl, modifiedParams) => {
3692
- const urlToHit = new URL(originalUrl.toString());
3693
- urlToHit.host = isEmpty(modifiedParams.port) ? `${modifiedParams.host}:${modifiedParams.port}` : modifiedParams.host;
3694
- return urlToHit;
3695
- };
3696
- var DEFAULT_OPTIONS2 = {
3697
- dnsCache: new DnsCacheResolver(),
3698
- headerFactory: (headers) => new Headers(headers || {})
3699
- };
3700
- var fetchCatchDns = (fetch3, {
3701
- dnsCache = new DnsCacheResolver(),
3702
- headerFactory = (headers) => new Headers(headers || {})
3703
- } = DEFAULT_OPTIONS2) => {
3704
- const fetchWithDns = async (input, options) => {
3705
- const parsedUrl = new URL(input.toString());
3706
- const { hostname, host, port } = parsedUrl;
3707
- if ((0, import_net.isIP)(hostname)) {
3708
- return await fetch3(input, options);
3709
- }
3710
- const maybeTargetIp = await dnsCache.resolve(hostname);
3711
- if (isEmpty(maybeTargetIp)) {
3712
- return await fetch3(input, options);
3713
- }
3714
- const target = toMaybeUrl(input, {
3715
- ...parsedUrl,
3716
- host: maybeTargetIp,
3717
- port
3718
- });
3719
- const headersOverride = headerFactory(options?.headers ?? {});
3720
- if (!headersOverride.has("Host")) {
3721
- headersOverride.set("Host", host);
3722
- }
3723
- const optionsOverride = {
3724
- ...options,
3725
- headers: headersOverride
3726
- };
3727
- try {
3728
- const res = await fetch3(target.toString(), optionsOverride);
3729
- return res;
3730
- } catch (e) {
3731
- if (e && e?.code === "ETIMEDOUT") {
3732
- dnsCache.removeCache(hostname);
3696
+ var baseOrkesConductorClient = (fetchFn, baseRequestHandler = defaultRequestHandler2) => {
3697
+ const requestTokenForKeySecret = (keyId, keySecret, tokenUrl) => fetchFn(tokenUrl, {
3698
+ headers: {
3699
+ "Content-Type": "application/json",
3700
+ Accept: "application/json"
3701
+ },
3702
+ body: JSON.stringify({ keyId, keySecret }),
3703
+ method: "POST"
3704
+ });
3705
+ return async (config, requestHandler = baseRequestHandler) => {
3706
+ if (config?.keySecret != null && config?.keyId != null) {
3707
+ const {
3708
+ serverUrl,
3709
+ keyId,
3710
+ keySecret,
3711
+ refreshTokenInterval = REFRESH_TOKEN_IN_MILLISECONDS
3712
+ } = config;
3713
+ const tokenUrl = `${serverUrl}/token`;
3714
+ const res = await requestTokenForKeySecret(keyId, keySecret, tokenUrl);
3715
+ const { token } = await res.json();
3716
+ const conductorClientInstance = new AuthConductorClient(
3717
+ { ...config, TOKEN: token },
3718
+ requestHandler
3719
+ );
3720
+ if (token != null && refreshTokenInterval > 0) {
3721
+ const intervalId = setInterval(async () => {
3722
+ const res2 = await requestTokenForKeySecret(
3723
+ keyId,
3724
+ keySecret,
3725
+ tokenUrl
3726
+ );
3727
+ const { token: token2 } = await res2.json();
3728
+ conductorClientInstance.token = token2;
3729
+ }, refreshTokenInterval);
3730
+ conductorClientInstance.intervalId = intervalId;
3733
3731
  }
3734
- throw e;
3732
+ return conductorClientInstance;
3733
+ } else {
3734
+ return new ConductorClient(config, requestHandler);
3735
3735
  }
3736
3736
  };
3737
- return fetchWithDns;
3738
3737
  };
3739
3738
 
3739
+ // src/orkes/OrkesConductorClient.ts
3740
+ var defaultRequestHandler3 = (request3, config, options) => request3(config, options);
3741
+ var orkesConductorClient = baseOrkesConductorClient(
3742
+ fetch,
3743
+ defaultRequestHandler3
3744
+ );
3745
+
3740
3746
  // src/orkes/request/request.ts
3741
3747
  var isDefined2 = (value) => {
3742
3748
  return value !== void 0 && value !== null;
@@ -3971,92 +3977,6 @@ var request2 = (config, options, fetchFn = fetch) => {
3971
3977
  }
3972
3978
  });
3973
3979
  };
3974
-
3975
- // src/orkes/BaseOrkesConductorClient.ts
3976
- var defaultRequestHandler2 = (request3, config, options) => request3(config, options);
3977
- var REFRESH_TOKEN_IN_MILLISECONDS = 30 * 60 * 1e3;
3978
- var AuthConductorClient = class extends ConductorClient {
3979
- constructor(config, requestHandler = defaultRequestHandler2) {
3980
- super(config, requestHandler);
3981
- }
3982
- /**
3983
- * Stops the interval that refreshes the token
3984
- */
3985
- stop() {
3986
- if (this.intervalId != null) {
3987
- clearInterval(this.intervalId);
3988
- }
3989
- }
3990
- };
3991
- var baseOrkesConductorClient = (fetchFn, baseRequestHandler = defaultRequestHandler2) => {
3992
- const requestTokenForKeySecret = (keyId, keySecret, tokenUrl) => fetchFn(tokenUrl, {
3993
- headers: {
3994
- "Content-Type": "application/json",
3995
- Accept: "application/json"
3996
- },
3997
- body: JSON.stringify({ keyId, keySecret }),
3998
- method: "POST"
3999
- });
4000
- return async (config, requestHandler = baseRequestHandler) => {
4001
- if (config?.keySecret != null && config?.keyId != null) {
4002
- const {
4003
- serverUrl,
4004
- keyId,
4005
- keySecret,
4006
- refreshTokenInterval = REFRESH_TOKEN_IN_MILLISECONDS
4007
- } = config;
4008
- const tokenUrl = `${serverUrl}/token`;
4009
- const res = await requestTokenForKeySecret(keyId, keySecret, tokenUrl);
4010
- const { token } = await res.json();
4011
- const conductorClientInstance = new AuthConductorClient(
4012
- { ...config, TOKEN: token },
4013
- requestHandler
4014
- );
4015
- if (token != null && refreshTokenInterval > 0) {
4016
- const intervalId = setInterval(async () => {
4017
- const res2 = await requestTokenForKeySecret(
4018
- keyId,
4019
- keySecret,
4020
- tokenUrl
4021
- );
4022
- const { token: token2 } = await res2.json();
4023
- conductorClientInstance.token = token2;
4024
- }, refreshTokenInterval);
4025
- conductorClientInstance.intervalId = intervalId;
4026
- }
4027
- return conductorClientInstance;
4028
- } else {
4029
- return new ConductorClient(config, requestHandler);
4030
- }
4031
- };
4032
- };
4033
-
4034
- // src/orkes/OrkesConductorClient.ts
4035
- var import_node_fetch = __toESM(require("node-fetch"));
4036
- var import_http = __toESM(require("http"));
4037
- var import_https = __toESM(require("https"));
4038
- var httpAgent = new import_http.default.Agent({ keepAlive: true });
4039
- var httpsAgent = new import_https.default.Agent({ keepAlive: true });
4040
- var agent = (_parsedURL) => _parsedURL.protocol == "http:" ? httpAgent : httpsAgent;
4041
- var nodeFetchWrapper = async (input, options = {}) => {
4042
- const res = await (0, import_node_fetch.default)(input.toString(), {
4043
- ...options,
4044
- agent
4045
- });
4046
- return res;
4047
- };
4048
- var fetchCache = fetchCatchDns(
4049
- nodeFetchWrapper,
4050
- {
4051
- //@ts-ignore
4052
- headerFactory: (headers) => new import_node_fetch.Headers(headers || {})
4053
- }
4054
- );
4055
- var defaultRequestHandler3 = (__request, config, options) => request2(config, options, fetchCache);
4056
- var orkesConductorClient = baseOrkesConductorClient(
4057
- fetchCache,
4058
- defaultRequestHandler3
4059
- );
4060
3980
  // Annotate the CommonJS export names for ESM import in node:
4061
3981
  0 && (module.exports = {
4062
3982
  ApiError,
@@ -4067,7 +3987,6 @@ var orkesConductorClient = baseOrkesConductorClient(
4067
3987
  ConductorClient,
4068
3988
  ConductorError,
4069
3989
  DefaultLogger,
4070
- DnsCacheResolver,
4071
3990
  EventResourceService,
4072
3991
  HealthCheckResourceService,
4073
3992
  HumanExecutor,
@@ -4087,7 +4006,6 @@ var orkesConductorClient = baseOrkesConductorClient(
4087
4006
  doWhileTask,
4088
4007
  dynamicForkTask,
4089
4008
  eventTask,
4090
- fetchCatchDns,
4091
4009
  forkTask,
4092
4010
  forkTaskJoin,
4093
4011
  generate,
@@ -4122,7 +4040,6 @@ var orkesConductorClient = baseOrkesConductorClient(
4122
4040
  switchTask,
4123
4041
  taskGenMapper,
4124
4042
  terminateTask,
4125
- toMaybeUrl,
4126
4043
  waitTaskDuration,
4127
4044
  waitTaskUntil,
4128
4045
  workflow