@hatchet-dev/typescript-sdk 1.19.1 → 1.19.2-alpha.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "1.19.1",
3
+ "version": "1.19.2-alpha.1",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -48,7 +48,7 @@
48
48
  "dependencies": {
49
49
  "@bufbuild/protobuf": "^2.11.0",
50
50
  "@types/qs": "^6.15.0",
51
- "abort-controller-x": "^0.4.3",
51
+ "abort-controller-x": "^0.5.0",
52
52
  "axios": "^1.13.5",
53
53
  "long": "^5.3.1",
54
54
  "nice-grpc": "^2.1.14",
@@ -64,8 +64,8 @@
64
64
  "@grpc/grpc-js": "^1.14.3",
65
65
  "@opentelemetry/api": "^1.9.0",
66
66
  "@opentelemetry/core": "^2.0.0",
67
- "@opentelemetry/exporter-trace-otlp-grpc": "^0.208.0",
68
- "@opentelemetry/instrumentation": "^0.208.0",
67
+ "@opentelemetry/exporter-trace-otlp-grpc": "^0.214.0",
68
+ "@opentelemetry/instrumentation": "^0.214.0",
69
69
  "@opentelemetry/sdk-trace-base": "^2.0.0",
70
70
  "prom-client": "^15.1.3"
71
71
  },
@@ -95,10 +95,10 @@ class InternalWorker {
95
95
  this.labels = options.labels || {};
96
96
  this.enableHealthServer = (_b = (_a = client.config.healthcheck) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : false;
97
97
  this.healthPort = (_d = (_c = client.config.healthcheck) === null || _c === void 0 ? void 0 : _c.port) !== null && _d !== void 0 ? _d : 8001;
98
- process.on('SIGTERM', () => this.exitGracefully(true));
99
- process.on('SIGINT', () => this.exitGracefully(true));
100
98
  this.killing = false;
101
99
  this.handle_kill = options.handleKill === undefined ? true : options.handleKill;
100
+ process.on('SIGTERM', () => this.exitGracefully(this.handle_kill));
101
+ process.on('SIGINT', () => this.exitGracefully(this.handle_kill));
102
102
  this.logger = client.config.logger(`Worker/${this.name}`, this.client.config.log_level);
103
103
  if (this.enableHealthServer && this.healthPort) {
104
104
  this.initializeHealthServer();
package/v1/declaration.js CHANGED
@@ -63,9 +63,7 @@ class BaseWorkflowDeclaration {
63
63
  if (!this.client) {
64
64
  throw UNBOUND_ERR;
65
65
  }
66
- // set the parent run context
67
66
  const parentRunContext = parent_run_context_vars_1.parentRunContextManager.getContext();
68
- parent_run_context_vars_1.parentRunContextManager.incrementChildIndex(Array.isArray(input) ? input.length : 1);
69
67
  if (!parentRunContext && ((options === null || options === void 0 ? void 0 : options.childKey) || (options === null || options === void 0 ? void 0 : options.sticky))) {
70
68
  this.client.admin.logger.warn('ignoring childKey or sticky because run is not being spawned from a parent task');
71
69
  }
@@ -79,20 +77,22 @@ class BaseWorkflowDeclaration {
79
77
  : undefined,
80
78
  warn: (message) => this.client.admin.logger.warn(message),
81
79
  });
82
- parent_run_context_vars_1.parentRunContextManager.incrementChildIndex(Array.isArray(input) ? input.length : 1);
83
- const runOpts = Object.assign(Object.assign({}, (options !== null && options !== void 0 ? options : {})), { parentId: parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.parentId, parentTaskRunExternalId: parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.parentTaskRunExternalId, childIndex: parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.childIndex, sticky: (options === null || options === void 0 ? void 0 : options.sticky) ? parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.desiredWorkerId : undefined, childKey: options === null || options === void 0 ? void 0 : options.childKey });
80
+ // Snapshot the base child index before incrementing. We use 1-based child
81
+ // indices because Context.spawnIndex occupies the 0-based range.
82
+ const baseChildIndex = parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.childIndex;
83
+ const inputCount = Array.isArray(input) ? input.length : 1;
84
+ parent_run_context_vars_1.parentRunContextManager.incrementChildIndex(inputCount);
85
+ const childIndexForRun = baseChildIndex != null ? baseChildIndex + 1 : undefined;
86
+ const runOpts = Object.assign(Object.assign({}, (options !== null && options !== void 0 ? options : {})), { parentId: parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.parentId, parentTaskRunExternalId: parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.parentTaskRunExternalId, childIndex: childIndexForRun, sticky: (options === null || options === void 0 ? void 0 : options.sticky) ? parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.desiredWorkerId : undefined, childKey: options === null || options === void 0 ? void 0 : options.childKey });
84
87
  if (Array.isArray(input)) {
85
88
  let resp = [];
86
89
  for (let i = 0; i < input.length; i += 500) {
87
90
  const batch = input.slice(i, i + 500);
88
- const batchResp = yield this.client.admin.runWorkflows(batch.map((inp) => {
89
- var _a;
90
- return ({
91
- workflowName: this.definition.name,
92
- input: inp,
93
- options: Object.assign(Object.assign({}, runOpts), { childIndex: ((_a = runOpts.childIndex) !== null && _a !== void 0 ? _a : 0) + i }),
94
- });
95
- }));
91
+ const batchResp = yield this.client.admin.runWorkflows(batch.map((inp, batchIdx) => ({
92
+ workflowName: this.definition.name,
93
+ input: inp,
94
+ options: Object.assign(Object.assign({}, runOpts), { childIndex: (childIndexForRun !== null && childIndexForRun !== void 0 ? childIndexForRun : 0) + i + batchIdx }),
95
+ })));
96
96
  resp = resp.concat(batchResp);
97
97
  }
98
98
  const res = [];
@@ -1,4 +1,4 @@
1
- import { DurableContext } from './client/worker/context';
1
+ import type { DurableContext } from './client/worker/context';
2
2
  export interface ParentRunContext {
3
3
  parentId: string;
4
4
  /**
@@ -16,18 +16,16 @@ class ParentRunContextManager {
16
16
  var _a;
17
17
  const parentRunContext = this.getContext();
18
18
  if (parentRunContext) {
19
- parentRunContext.parentId = opts.parentId;
20
- parentRunContext.parentTaskRunExternalId = opts.parentTaskRunExternalId;
21
- parentRunContext.childIndex = ((_a = parentRunContext.childIndex) !== null && _a !== void 0 ? _a : 0) + 1;
22
- this.setContext(parentRunContext);
19
+ this.setContext(Object.assign(Object.assign({}, parentRunContext), { parentId: opts.parentId, parentTaskRunExternalId: opts.parentTaskRunExternalId, childIndex: ((_a = parentRunContext.childIndex) !== null && _a !== void 0 ? _a : 0) + 1 }));
23
20
  }
24
21
  }
25
22
  incrementChildIndex(n) {
26
23
  var _a;
27
24
  const parentRunContext = this.getContext();
28
25
  if (parentRunContext) {
29
- parentRunContext.childIndex = ((_a = parentRunContext.childIndex) !== null && _a !== void 0 ? _a : 0) + n;
30
- this.setContext(parentRunContext);
26
+ // Build a fresh object to avoid mutating the live store reference, which
27
+ // would corrupt any values snapshotted before this call.
28
+ this.setContext(Object.assign(Object.assign({}, parentRunContext), { childIndex: ((_a = parentRunContext.childIndex) !== null && _a !== void 0 ? _a : 0) + n }));
31
29
  }
32
30
  }
33
31
  getContext() {
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const HATCHET_VERSION = "1.19.1";
1
+ export declare const HATCHET_VERSION = "1.19.2-alpha.1";
package/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HATCHET_VERSION = void 0;
4
- exports.HATCHET_VERSION = '1.19.1';
4
+ exports.HATCHET_VERSION = '1.19.2-alpha.1';