@io-orkes/conductor-javascript 1.2.1-rc.1 → 1.2.1-rc.3

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 CHANGED
@@ -45,6 +45,7 @@ import { OrkesApiConfig, orkesConductorClient } from "@io-orkes/conductor-javasc
45
45
  const config: Partial<OrkesApiConfig> = {
46
46
  keyId: "XXX", // optional
47
47
  keySecret: "XXXX", // optional
48
+ refreshTokenInterval: 0 // optional (in milliseconds) defaults to 30 minutes (30 * 60 * 1000). 0 no refresh
48
49
  serverUrl: "https://play.orkes.io/api",
49
50
  };
50
51
 
@@ -1,5 +1,5 @@
1
- import { O as OrkesApiConfig, C as ConductorHttpRequest, a as ConductorClient } from './types-9addaabb.js';
2
- export { p as Action, m as ApiError, A as ApiRequestOptions, k as ApiResult, a6 as AssignmentPolicy, a8 as BackToAssigment, B as BaseHttpRequest, o as CancelError, d as CancelablePromise, a9 as ClearAssigment, au as CommonTaskDef, b as ConductorClientAPIConfig, aR as ConductorError, ap as ConductorLogLevel, ao as ConductorLogger, j as ConductorWorker, ar as DefaultLogger, aq as DefaultLoggerConfig, ax as DoWhileTaskDef, aa as Escalate, E as EventHandler, _ as EventResourceService, ay as EventTaskDef, q as ExternalStorageLocation, ab as FFAAssignment, F as FetchFn, a7 as Fixed, aB as ForkJoinDynamicDef, az as ForkJoinTaskDef, G as GenerateTokenRequest, ac as HTScrollableSearchResultHumanTaskEntry, $ as HealthCheckResourceService, aC as HttpInputParameters, aD as HttpTaskDef, aT as HumanExecutor, ad as HumanTaskActionLogEntry, ae as HumanTaskEntry, af as HumanTaskLoad, ag as HumanTaskStateLogEntry, ah as HumanTaskTemplate, ai as HumanTaskTemplateEntry, aF as InlineTaskDef, aE as InlineTaskInputParameters, aA as JoinTaskDef, aG as JsonJQTransformTaskDef, aH as KafkaPublishInputParameters, aI as KafkaPublishTaskDef, aj as LeastBusyGroupMemberAssignment, a0 as MetadataResourceService, ak as Never, l as OnCancel, c as OpenAPIConfig, P as PollData, at as RequestType, r as RerunWorkflowRequest, s as Response, R as RunnerArgs, S as SaveScheduleRequest, a1 as SchedulerResourceService, t as ScrollableSearchResultWorkflowSummary, al as SearchResultHumanTaskEntry, u as SearchResultTask, v as SearchResultTaskSummary, w as SearchResultWorkflow, x as SearchResultWorkflowScheduleExecutionModel, y as SearchResultWorkflowSummary, aJ as SetVariableTaskDef, aK as SimpleTaskDef, z as SkipTaskRequest, D as StartWorkflow, H as StartWorkflowRequest, I as SubWorkflowParams, aL as SubWorkflowTaskDef, aM as SwitchTaskDef, J as Task, K as TaskDef, aw as TaskDefTypes, L as TaskDetails, T as TaskErrorHandler, M as TaskExecLog, i as TaskManager, h as TaskManagerConfig, g as TaskManagerOptions, a2 as TaskResourceService, N as TaskResult, aS as TaskResultStatus, f as TaskRunner, e as TaskRunnerOptions, Q as TaskSummary, av as TaskType, am as Terminate, aN as TerminateTaskDef, an as TimeoutPolicy, a3 as TokenResourceService, aO as WaitTaskDef, W as Workflow, a4 as WorkflowBulkResourceService, aP as WorkflowDef, aQ as WorkflowExecutor, a5 as WorkflowResourceService, U as WorkflowSchedule, V as WorkflowScheduleExecutionModel, X as WorkflowStatus, Y as WorkflowSummary, Z as WorkflowTask, aZ as conductorEventTask, aU as doWhileTask, aW as dynamicForkTask, aX as eventTask, a_ as forkTask, a$ as forkTaskJoin, br as generate, be as generateDoWhileTask, bf as generateEventTask, bg as generateForkJoinTask, bi as generateHTTPTask, bj as generateInlineTask, bk as generateJQTransformTask, bh as generateJoinTask, bl as generateKafkaPublishTask, bn as generateSetVariableTask, bd as generateSimpleTask, bm as generateSubWorkflowTask, bq as generateSwitchTask, bo as generateTerminateTask, bp as generateWaitTask, b0 as httpTask, b1 as inlineTask, b2 as joinTask, b3 as jsonJqTask, b4 as kafkaPublishTask, aV as newLoopTask, n as noopErrorHandler, as as noopLogger, b5 as setVariableTask, b6 as simpleTask, aY as sqsEventTask, b7 as subWorkflowTask, b8 as switchTask, bs as taskGenMapper, b9 as terminateTask, ba as waitTaskDuration, bb as waitTaskUntil, bc as workflow } from './types-9addaabb.js';
1
+ import { O as OrkesApiConfig, C as ConductorHttpRequest, a as ConductorClient } from './types-1e3272c6.js';
2
+ export { p as Action, m as ApiError, A as ApiRequestOptions, k as ApiResult, a6 as AssignmentPolicy, a8 as BackToAssigment, B as BaseHttpRequest, o as CancelError, d as CancelablePromise, a9 as ClearAssigment, au as CommonTaskDef, b as ConductorClientAPIConfig, aR as ConductorError, ap as ConductorLogLevel, ao as ConductorLogger, j as ConductorWorker, ar as DefaultLogger, aq as DefaultLoggerConfig, ax as DoWhileTaskDef, aa as Escalate, E as EventHandler, _ as EventResourceService, ay as EventTaskDef, q as ExternalStorageLocation, ab as FFAAssignment, F as FetchFn, a7 as Fixed, aB as ForkJoinDynamicDef, az as ForkJoinTaskDef, G as GenerateTokenRequest, ac as HTScrollableSearchResultHumanTaskEntry, $ as HealthCheckResourceService, aC as HttpInputParameters, aD as HttpTaskDef, aT as HumanExecutor, ad as HumanTaskActionLogEntry, ae as HumanTaskEntry, af as HumanTaskLoad, ag as HumanTaskStateLogEntry, ah as HumanTaskTemplate, ai as HumanTaskTemplateEntry, aF as InlineTaskDef, aE as InlineTaskInputParameters, aA as JoinTaskDef, aG as JsonJQTransformTaskDef, aH as KafkaPublishInputParameters, aI as KafkaPublishTaskDef, aj as LeastBusyGroupMemberAssignment, a0 as MetadataResourceService, ak as Never, l as OnCancel, c as OpenAPIConfig, P as PollData, at as RequestType, r as RerunWorkflowRequest, s as Response, R as RunnerArgs, S as SaveScheduleRequest, a1 as SchedulerResourceService, t as ScrollableSearchResultWorkflowSummary, al as SearchResultHumanTaskEntry, u as SearchResultTask, v as SearchResultTaskSummary, w as SearchResultWorkflow, x as SearchResultWorkflowScheduleExecutionModel, y as SearchResultWorkflowSummary, aJ as SetVariableTaskDef, aK as SimpleTaskDef, z as SkipTaskRequest, D as StartWorkflow, H as StartWorkflowRequest, I as SubWorkflowParams, aL as SubWorkflowTaskDef, aM as SwitchTaskDef, J as Task, K as TaskDef, aw as TaskDefTypes, L as TaskDetails, T as TaskErrorHandler, M as TaskExecLog, i as TaskManager, h as TaskManagerConfig, g as TaskManagerOptions, a2 as TaskResourceService, N as TaskResult, aS as TaskResultStatus, f as TaskRunner, e as TaskRunnerOptions, Q as TaskSummary, av as TaskType, am as Terminate, aN as TerminateTaskDef, an as TimeoutPolicy, a3 as TokenResourceService, aO as WaitTaskDef, W as Workflow, a4 as WorkflowBulkResourceService, aP as WorkflowDef, aQ as WorkflowExecutor, a5 as WorkflowResourceService, U as WorkflowSchedule, V as WorkflowScheduleExecutionModel, X as WorkflowStatus, Y as WorkflowSummary, Z as WorkflowTask, aZ as conductorEventTask, aU as doWhileTask, aW as dynamicForkTask, aX as eventTask, a_ as forkTask, a$ as forkTaskJoin, br as generate, be as generateDoWhileTask, bf as generateEventTask, bg as generateForkJoinTask, bi as generateHTTPTask, bj as generateInlineTask, bk as generateJQTransformTask, bh as generateJoinTask, bl as generateKafkaPublishTask, bn as generateSetVariableTask, bd as generateSimpleTask, bm as generateSubWorkflowTask, bq as generateSwitchTask, bo as generateTerminateTask, bp as generateWaitTask, b0 as httpTask, b1 as inlineTask, b2 as joinTask, b3 as jsonJqTask, b4 as kafkaPublishTask, aV as newLoopTask, n as noopErrorHandler, as as noopLogger, b5 as setVariableTask, b6 as simpleTask, aY as sqsEventTask, b7 as subWorkflowTask, b8 as switchTask, bs as taskGenMapper, b9 as terminateTask, ba as waitTaskDuration, bb as waitTaskUntil, bc as workflow } from './types-1e3272c6.js';
3
3
 
4
4
  /**
5
5
  * Takes a config with keyId and keySecret returns a promise with an instance of ConductorClient
package/dist/browser.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { O as OrkesApiConfig, C as ConductorHttpRequest, a as ConductorClient } from './types-9addaabb.js';
2
- export { p as Action, m as ApiError, A as ApiRequestOptions, k as ApiResult, a6 as AssignmentPolicy, a8 as BackToAssigment, B as BaseHttpRequest, o as CancelError, d as CancelablePromise, a9 as ClearAssigment, au as CommonTaskDef, b as ConductorClientAPIConfig, aR as ConductorError, ap as ConductorLogLevel, ao as ConductorLogger, j as ConductorWorker, ar as DefaultLogger, aq as DefaultLoggerConfig, ax as DoWhileTaskDef, aa as Escalate, E as EventHandler, _ as EventResourceService, ay as EventTaskDef, q as ExternalStorageLocation, ab as FFAAssignment, F as FetchFn, a7 as Fixed, aB as ForkJoinDynamicDef, az as ForkJoinTaskDef, G as GenerateTokenRequest, ac as HTScrollableSearchResultHumanTaskEntry, $ as HealthCheckResourceService, aC as HttpInputParameters, aD as HttpTaskDef, aT as HumanExecutor, ad as HumanTaskActionLogEntry, ae as HumanTaskEntry, af as HumanTaskLoad, ag as HumanTaskStateLogEntry, ah as HumanTaskTemplate, ai as HumanTaskTemplateEntry, aF as InlineTaskDef, aE as InlineTaskInputParameters, aA as JoinTaskDef, aG as JsonJQTransformTaskDef, aH as KafkaPublishInputParameters, aI as KafkaPublishTaskDef, aj as LeastBusyGroupMemberAssignment, a0 as MetadataResourceService, ak as Never, l as OnCancel, c as OpenAPIConfig, P as PollData, at as RequestType, r as RerunWorkflowRequest, s as Response, R as RunnerArgs, S as SaveScheduleRequest, a1 as SchedulerResourceService, t as ScrollableSearchResultWorkflowSummary, al as SearchResultHumanTaskEntry, u as SearchResultTask, v as SearchResultTaskSummary, w as SearchResultWorkflow, x as SearchResultWorkflowScheduleExecutionModel, y as SearchResultWorkflowSummary, aJ as SetVariableTaskDef, aK as SimpleTaskDef, z as SkipTaskRequest, D as StartWorkflow, H as StartWorkflowRequest, I as SubWorkflowParams, aL as SubWorkflowTaskDef, aM as SwitchTaskDef, J as Task, K as TaskDef, aw as TaskDefTypes, L as TaskDetails, T as TaskErrorHandler, M as TaskExecLog, i as TaskManager, h as TaskManagerConfig, g as TaskManagerOptions, a2 as TaskResourceService, N as TaskResult, aS as TaskResultStatus, f as TaskRunner, e as TaskRunnerOptions, Q as TaskSummary, av as TaskType, am as Terminate, aN as TerminateTaskDef, an as TimeoutPolicy, a3 as TokenResourceService, aO as WaitTaskDef, W as Workflow, a4 as WorkflowBulkResourceService, aP as WorkflowDef, aQ as WorkflowExecutor, a5 as WorkflowResourceService, U as WorkflowSchedule, V as WorkflowScheduleExecutionModel, X as WorkflowStatus, Y as WorkflowSummary, Z as WorkflowTask, aZ as conductorEventTask, aU as doWhileTask, aW as dynamicForkTask, aX as eventTask, a_ as forkTask, a$ as forkTaskJoin, br as generate, be as generateDoWhileTask, bf as generateEventTask, bg as generateForkJoinTask, bi as generateHTTPTask, bj as generateInlineTask, bk as generateJQTransformTask, bh as generateJoinTask, bl as generateKafkaPublishTask, bn as generateSetVariableTask, bd as generateSimpleTask, bm as generateSubWorkflowTask, bq as generateSwitchTask, bo as generateTerminateTask, bp as generateWaitTask, b0 as httpTask, b1 as inlineTask, b2 as joinTask, b3 as jsonJqTask, b4 as kafkaPublishTask, aV as newLoopTask, n as noopErrorHandler, as as noopLogger, b5 as setVariableTask, b6 as simpleTask, aY as sqsEventTask, b7 as subWorkflowTask, b8 as switchTask, bs as taskGenMapper, b9 as terminateTask, ba as waitTaskDuration, bb as waitTaskUntil, bc as workflow } from './types-9addaabb.js';
1
+ import { O as OrkesApiConfig, C as ConductorHttpRequest, a as ConductorClient } from './types-1e3272c6.js';
2
+ export { p as Action, m as ApiError, A as ApiRequestOptions, k as ApiResult, a6 as AssignmentPolicy, a8 as BackToAssigment, B as BaseHttpRequest, o as CancelError, d as CancelablePromise, a9 as ClearAssigment, au as CommonTaskDef, b as ConductorClientAPIConfig, aR as ConductorError, ap as ConductorLogLevel, ao as ConductorLogger, j as ConductorWorker, ar as DefaultLogger, aq as DefaultLoggerConfig, ax as DoWhileTaskDef, aa as Escalate, E as EventHandler, _ as EventResourceService, ay as EventTaskDef, q as ExternalStorageLocation, ab as FFAAssignment, F as FetchFn, a7 as Fixed, aB as ForkJoinDynamicDef, az as ForkJoinTaskDef, G as GenerateTokenRequest, ac as HTScrollableSearchResultHumanTaskEntry, $ as HealthCheckResourceService, aC as HttpInputParameters, aD as HttpTaskDef, aT as HumanExecutor, ad as HumanTaskActionLogEntry, ae as HumanTaskEntry, af as HumanTaskLoad, ag as HumanTaskStateLogEntry, ah as HumanTaskTemplate, ai as HumanTaskTemplateEntry, aF as InlineTaskDef, aE as InlineTaskInputParameters, aA as JoinTaskDef, aG as JsonJQTransformTaskDef, aH as KafkaPublishInputParameters, aI as KafkaPublishTaskDef, aj as LeastBusyGroupMemberAssignment, a0 as MetadataResourceService, ak as Never, l as OnCancel, c as OpenAPIConfig, P as PollData, at as RequestType, r as RerunWorkflowRequest, s as Response, R as RunnerArgs, S as SaveScheduleRequest, a1 as SchedulerResourceService, t as ScrollableSearchResultWorkflowSummary, al as SearchResultHumanTaskEntry, u as SearchResultTask, v as SearchResultTaskSummary, w as SearchResultWorkflow, x as SearchResultWorkflowScheduleExecutionModel, y as SearchResultWorkflowSummary, aJ as SetVariableTaskDef, aK as SimpleTaskDef, z as SkipTaskRequest, D as StartWorkflow, H as StartWorkflowRequest, I as SubWorkflowParams, aL as SubWorkflowTaskDef, aM as SwitchTaskDef, J as Task, K as TaskDef, aw as TaskDefTypes, L as TaskDetails, T as TaskErrorHandler, M as TaskExecLog, i as TaskManager, h as TaskManagerConfig, g as TaskManagerOptions, a2 as TaskResourceService, N as TaskResult, aS as TaskResultStatus, f as TaskRunner, e as TaskRunnerOptions, Q as TaskSummary, av as TaskType, am as Terminate, aN as TerminateTaskDef, an as TimeoutPolicy, a3 as TokenResourceService, aO as WaitTaskDef, W as Workflow, a4 as WorkflowBulkResourceService, aP as WorkflowDef, aQ as WorkflowExecutor, a5 as WorkflowResourceService, U as WorkflowSchedule, V as WorkflowScheduleExecutionModel, X as WorkflowStatus, Y as WorkflowSummary, Z as WorkflowTask, aZ as conductorEventTask, aU as doWhileTask, aW as dynamicForkTask, aX as eventTask, a_ as forkTask, a$ as forkTaskJoin, br as generate, be as generateDoWhileTask, bf as generateEventTask, bg as generateForkJoinTask, bi as generateHTTPTask, bj as generateInlineTask, bk as generateJQTransformTask, bh as generateJoinTask, bl as generateKafkaPublishTask, bn as generateSetVariableTask, bd as generateSimpleTask, bm as generateSubWorkflowTask, bq as generateSwitchTask, bo as generateTerminateTask, bp as generateWaitTask, b0 as httpTask, b1 as inlineTask, b2 as joinTask, b3 as jsonJqTask, b4 as kafkaPublishTask, aV as newLoopTask, n as noopErrorHandler, as as noopLogger, b5 as setVariableTask, b6 as simpleTask, aY as sqsEventTask, b7 as subWorkflowTask, b8 as switchTask, bs as taskGenMapper, b9 as terminateTask, ba as waitTaskDuration, bb as waitTaskUntil, bc as workflow } from './types-1e3272c6.js';
3
3
 
4
4
  /**
5
5
  * Takes a config with keyId and keySecret returns a promise with an instance of ConductorClient
package/dist/browser.js CHANGED
@@ -2283,14 +2283,17 @@ var BaseHttpRequest = class {
2283
2283
 
2284
2284
  // src/task/Poller.ts
2285
2285
  var Poller = class {
2286
- constructor(pollFunction, pollerOptions, logger) {
2287
- this.concurrentCalls = [];
2288
- this.pollFunction = async () => {
2286
+ constructor(pollerId, pollFunction, performWorkFunction, pollerOptions, logger) {
2287
+ this.performWorkFunction = async () => {
2289
2288
  };
2290
2289
  this.polling = false;
2290
+ this._tasksInProcess = 0;
2291
+ this._counterAtO = 0;
2292
+ this._pollerId = "";
2291
2293
  this.options = {
2292
- pollInterval: 1e3,
2293
- concurrency: 1
2294
+ pollInterval: 100,
2295
+ concurrency: 1,
2296
+ warnAtO: 100
2294
2297
  };
2295
2298
  this.logger = noopLogger;
2296
2299
  /**
@@ -2300,78 +2303,69 @@ var Poller = class {
2300
2303
  if (this.polling) {
2301
2304
  throw new Error("Runner is already started");
2302
2305
  }
2303
- return this.poll();
2306
+ this._tasksInProcess = 0;
2307
+ this.polling = true;
2308
+ this.poll();
2304
2309
  };
2305
2310
  /**
2306
2311
  * Stops Polling for work
2307
2312
  */
2308
2313
  this.stopPolling = async () => {
2309
- await Promise.all(this.concurrentCalls.map((call) => call.stop()));
2310
2314
  this.polling = false;
2315
+ clearTimeout(this.timeoutHandler);
2311
2316
  };
2312
- this.poll = async () => {
2313
- if (!this.polling) {
2314
- this.polling = true;
2315
- for (let i = 0; i < this.options.concurrency; i++) {
2316
- this.concurrentCalls.push(this.singlePoll());
2317
- }
2318
- }
2317
+ this.performWork = async (work) => {
2318
+ await this.performWorkFunction(work);
2319
+ this._tasksInProcess--;
2319
2320
  };
2320
- this.singlePoll = () => {
2321
- let poll = this.polling;
2322
- let timeout;
2323
- const pollingCall = async () => {
2324
- while (poll) {
2325
- await this.pollFunction();
2326
- await new Promise(
2327
- (r) => poll ? timeout = setTimeout(() => r(true), this.options.pollInterval) : r(true)
2321
+ this.poll = async () => {
2322
+ while (this.isPolling) {
2323
+ try {
2324
+ const count = Math.max(
2325
+ 0,
2326
+ this.options.concurrency - this._tasksInProcess
2328
2327
  );
2328
+ if (count == 0) {
2329
+ this.logger.debug(
2330
+ "Max in process reached, Will skip polling for " + this._pollerId
2331
+ );
2332
+ this._counterAtO++;
2333
+ if (this._counterAtO > (this.options.warnAtO ?? 100)) {
2334
+ this.logger.info(
2335
+ `Not polling anything because in process tasks is maxed as concurrency level. ${this._pollerId}`
2336
+ );
2337
+ }
2338
+ } else {
2339
+ this._counterAtO = 0;
2340
+ const tasksResult = await this.pollFunction(count);
2341
+ this._tasksInProcess = this._tasksInProcess + (tasksResult ?? []).length;
2342
+ tasksResult.forEach(this.performWork);
2343
+ }
2344
+ } catch (e) {
2345
+ this.logger.error(`Error polling for tasks: ${e.message}`, e);
2329
2346
  }
2330
- };
2331
- return {
2332
- promise: pollingCall(),
2333
- stop: () => new Promise((r) => {
2334
- clearTimeout(timeout);
2335
- poll = false;
2336
- this.logger.debug("stopping single poll call");
2337
- r(true);
2338
- })
2339
- };
2347
+ await new Promise(
2348
+ (r) => this.isPolling ? this.timeoutHandler = setTimeout(
2349
+ () => r(true),
2350
+ this.options.pollInterval
2351
+ ) : r(true)
2352
+ );
2353
+ }
2340
2354
  };
2355
+ this._pollerId = pollerId;
2341
2356
  this.pollFunction = pollFunction;
2357
+ this.performWorkFunction = performWorkFunction;
2342
2358
  this.options = { ...this.options, ...pollerOptions };
2343
2359
  this.logger = logger || noopLogger;
2344
2360
  }
2345
2361
  get isPolling() {
2346
2362
  return this.polling;
2347
2363
  }
2348
- /**
2349
- * adds or shuts down concurrent calls based on the concurrency setting
2350
- * @param concurrency
2351
- */
2352
- updateConcurrency(concurrency) {
2353
- if (concurrency > 0 && concurrency !== this.options.concurrency) {
2354
- if (concurrency < this.options.concurrency) {
2355
- const result = this.concurrentCalls.splice(
2356
- 0,
2357
- this.options.concurrency - concurrency
2358
- );
2359
- result.forEach((call) => {
2360
- call.stop();
2361
- this.logger.debug("stopping some spawned calls");
2362
- });
2363
- } else {
2364
- for (let i = 0; i < concurrency - this.options.concurrency; i++) {
2365
- this.concurrentCalls.push(this.singlePoll());
2366
- this.logger.debug("spawning additional poll calls");
2367
- }
2368
- }
2369
- this.options.concurrency = concurrency;
2370
- }
2364
+ get tasksInProcess() {
2365
+ return this._tasksInProcess;
2371
2366
  }
2372
2367
  updateOptions(options) {
2373
2368
  const newOptions = { ...this.options, ...options };
2374
- this.updateConcurrency(newOptions.concurrency);
2375
2369
  this.options = newOptions;
2376
2370
  }
2377
2371
  };
@@ -2381,6 +2375,13 @@ var DEFAULT_ERROR_MESSAGE = "An unknown error occurred";
2381
2375
  var MAX_RETRIES = 3;
2382
2376
  var noopErrorHandler = (__error) => {
2383
2377
  };
2378
+ var defaultRunnerOptions = {
2379
+ workerID: "",
2380
+ pollInterval: 100,
2381
+ domain: void 0,
2382
+ concurrency: 1,
2383
+ batchPollingTimeout: 100
2384
+ };
2384
2385
  var TaskRunner = class {
2385
2386
  constructor({
2386
2387
  worker,
@@ -2394,6 +2395,9 @@ var TaskRunner = class {
2394
2395
  */
2395
2396
  this.startPolling = () => {
2396
2397
  this.poller.startPolling();
2398
+ this.logger.info(
2399
+ `TaskWorker ${this.worker.taskDefName} initialized with concurrency of ${this.poller.options.concurrency} and poll interval of ${this.poller.options.pollInterval}`
2400
+ );
2397
2401
  };
2398
2402
  /**
2399
2403
  * Stops Polling for work
@@ -2401,23 +2405,17 @@ var TaskRunner = class {
2401
2405
  this.stopPolling = async () => {
2402
2406
  await this.poller.stopPolling();
2403
2407
  };
2404
- this.pollAndExecute = async () => {
2405
- try {
2406
- const { workerID } = this.options;
2407
- const task = await this.taskResource.poll(
2408
- this.worker.taskDefName,
2409
- workerID,
2410
- this.worker.domain ?? this.options.domain
2411
- );
2412
- if (task && task.taskId) {
2413
- await this.executeTask(task);
2414
- } else {
2415
- this.logger.debug(`No tasks for ${this.worker.taskDefName}`);
2416
- }
2417
- } catch (unknownError) {
2418
- this.handleUnknownError(unknownError);
2419
- this.errorHandler(unknownError);
2420
- }
2408
+ this.batchPoll = async (count) => {
2409
+ const { workerID } = this.options;
2410
+ const tasks = await this.taskResource.batchPoll(
2411
+ this.worker.taskDefName,
2412
+ workerID,
2413
+ this.worker.domain ?? this.options.domain,
2414
+ count,
2415
+ this.options.batchPollingTimeout ?? 100
2416
+ // default batch poll defined in the method
2417
+ );
2418
+ return tasks;
2421
2419
  };
2422
2420
  this.updateTaskWithRetry = async (task, taskResult) => {
2423
2421
  let retryCount = 0;
@@ -2476,11 +2474,16 @@ var TaskRunner = class {
2476
2474
  this.taskResource = taskResource;
2477
2475
  this.logger = logger;
2478
2476
  this.worker = worker;
2479
- this.options = options;
2477
+ this.options = { ...defaultRunnerOptions, ...options };
2480
2478
  this.errorHandler = errorHandler;
2481
2479
  this.poller = new Poller(
2482
- this.pollAndExecute,
2483
- { concurrency: options.concurrency, pollInterval: options.pollInterval },
2480
+ worker.taskDefName,
2481
+ this.batchPoll,
2482
+ this.executeTask,
2483
+ {
2484
+ concurrency: worker.concurrency ?? options.concurrency,
2485
+ pollInterval: worker.pollInterval ?? options.pollInterval
2486
+ },
2484
2487
  this.logger
2485
2488
  );
2486
2489
  }
@@ -2493,6 +2496,9 @@ var TaskRunner = class {
2493
2496
  concurrency: newOptions.concurrency,
2494
2497
  pollInterval: newOptions.pollInterval
2495
2498
  });
2499
+ this.logger.info(
2500
+ `TaskWorker ${this.worker.taskDefName} configuration updated with concurrency of ${this.poller.options.concurrency} and poll interval of ${this.poller.options.pollInterval}`
2501
+ );
2496
2502
  this.options = newOptions;
2497
2503
  }
2498
2504
  get getOptions() {
@@ -2504,24 +2510,36 @@ var TaskRunner = class {
2504
2510
  var import_os = __toESM(require("os"));
2505
2511
  var defaultManagerOptions = {
2506
2512
  workerID: "",
2507
- pollInterval: 1e3,
2513
+ pollInterval: 100,
2508
2514
  domain: void 0,
2509
- concurrency: 1
2515
+ concurrency: 1,
2516
+ batchPollingTimeout: 100
2510
2517
  };
2511
2518
  function workerId(options) {
2512
2519
  return options.workerID ?? import_os.default.hostname();
2513
2520
  }
2514
2521
  var TaskManager = class {
2515
2522
  constructor(client, workers, config = {}) {
2516
- this.tasks = {};
2523
+ this.workerRunners = /* @__PURE__ */ new Map();
2517
2524
  this.polling = false;
2518
2525
  this.workerManagerWorkerOptions = (worker) => {
2519
2526
  return {
2520
2527
  ...this.options,
2521
2528
  concurrency: worker.concurrency ?? this.options.concurrency,
2529
+ pollInterval: worker.pollInterval ?? this.options.pollInterval,
2522
2530
  domain: worker.domain ?? this.options.domain
2523
2531
  };
2524
2532
  };
2533
+ this.updatePollingOptionForWorker = (workerTaskDefName, options) => {
2534
+ const maybeRunner = this.workerRunners.get(workerTaskDefName);
2535
+ if (maybeRunner != null) {
2536
+ maybeRunner.updateOptions(options);
2537
+ } else {
2538
+ this.logger.info(
2539
+ `No runner found for worker with taskDefName: ${workerTaskDefName}`
2540
+ );
2541
+ }
2542
+ };
2525
2543
  /**
2526
2544
  * new options will get merged to existing options
2527
2545
  * @param options new options to update polling options
@@ -2532,24 +2550,30 @@ var TaskManager = class {
2532
2550
  ...this.workerManagerWorkerOptions(worker),
2533
2551
  ...options
2534
2552
  };
2535
- const runners = this.tasks[worker.taskDefName];
2536
- runners.forEach((runner) => {
2537
- runner.updateOptions(newOptions);
2538
- });
2553
+ this.updatePollingOptionForWorker(worker.taskDefName, newOptions);
2539
2554
  });
2540
2555
  this.options.concurrency = options.concurrency ?? this.options.concurrency;
2541
2556
  this.options.pollInterval = options.pollInterval ?? this.options.pollInterval;
2542
2557
  };
2558
+ this.sanityCheck = () => {
2559
+ if (this.workers.length === 0) {
2560
+ throw new Error("No workers supplied to TaskManager");
2561
+ }
2562
+ const workerIDs = /* @__PURE__ */ new Set();
2563
+ for (const item of this.workers) {
2564
+ if (workerIDs.has(item.taskDefName)) {
2565
+ throw new Error(`Duplicate worker taskDefName: ${item.taskDefName}`);
2566
+ }
2567
+ workerIDs.add(item.taskDefName);
2568
+ }
2569
+ };
2543
2570
  /**
2544
2571
  * Start polling for tasks
2545
2572
  */
2546
2573
  this.startPolling = () => {
2574
+ this.sanityCheck();
2547
2575
  this.workers.forEach((worker) => {
2548
- this.tasks[worker.taskDefName] = [];
2549
2576
  const options = this.workerManagerWorkerOptions(worker);
2550
- this.logger.debug(
2551
- `Starting taskDefName=${worker.taskDefName} concurrency=${options.concurrency} domain=${options.domain}`
2552
- );
2553
2577
  const runner = new TaskRunner({
2554
2578
  worker,
2555
2579
  options,
@@ -2558,7 +2582,7 @@ var TaskManager = class {
2558
2582
  onError: this.errorHandler
2559
2583
  });
2560
2584
  runner.startPolling();
2561
- this.tasks[worker.taskDefName].push(runner);
2585
+ this.workerRunners.set(worker.taskDefName, runner);
2562
2586
  });
2563
2587
  this.polling = true;
2564
2588
  };
@@ -2566,11 +2590,10 @@ var TaskManager = class {
2566
2590
  * Stops polling for tasks
2567
2591
  */
2568
2592
  this.stopPolling = async () => {
2569
- for (const taskType in this.tasks) {
2570
- await Promise.all(
2571
- this.tasks[taskType].map((runner) => runner.stopPolling())
2572
- );
2573
- this.tasks[taskType] = [];
2593
+ for (const [workerTaskDefName, runner] of this.workerRunners) {
2594
+ this.logger.debug(`Stopping taskDefName=${workerTaskDefName}`);
2595
+ await runner.stopPolling();
2596
+ this.workerRunners.delete(workerTaskDefName);
2574
2597
  }
2575
2598
  this.polling = false;
2576
2599
  };