@hatchet-dev/typescript-sdk 0.15.1-alpha0 → 0.15.1-alpha1

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.
@@ -11,6 +11,7 @@ export declare class Streamable {
11
11
  export declare class GrpcPooledListener {
12
12
  listener: AsyncIterable<WorkflowRunEvent> | undefined;
13
13
  requestEmitter: EventEmitter<[never]>;
14
+ signal: AbortController;
14
15
  client: ListenerClient;
15
16
  subscribers: Record<string, Streamable>;
16
17
  onFinish: () => void;
@@ -38,7 +38,7 @@ const events_1 = require("events");
38
38
  const dispatcher_1 = require("../../protoc/dispatcher");
39
39
  const abort_controller_x_1 = require("abort-controller-x");
40
40
  const sleep_1 = __importDefault(require("../../util/sleep"));
41
- const DEFAULT_EVENT_LISTENER_RETRY_INTERVAL = 0.5; // seconds
41
+ const DEFAULT_EVENT_LISTENER_RETRY_INTERVAL = 5; // seconds
42
42
  const DEFAULT_EVENT_LISTENER_RETRY_COUNT = 20;
43
43
  class Streamable {
44
44
  constructor(listener, id) {
@@ -61,6 +61,7 @@ exports.Streamable = Streamable;
61
61
  class GrpcPooledListener {
62
62
  constructor(client, onFinish) {
63
63
  this.requestEmitter = new events_1.EventEmitter();
64
+ this.signal = new AbortController();
64
65
  this.subscribers = {};
65
66
  this.onFinish = () => { };
66
67
  this.client = client;
@@ -78,7 +79,10 @@ class GrpcPooledListener {
78
79
  }
79
80
  try {
80
81
  this.client.logger.debug('Initializing child-listener');
81
- this.listener = this.client.client.subscribeToWorkflowRuns(this.request(), {});
82
+ this.signal = new AbortController();
83
+ this.listener = this.client.client.subscribeToWorkflowRuns(this.request(), {
84
+ signal: this.signal.signal,
85
+ });
82
86
  if (retries > 0)
83
87
  setTimeout(() => this.replayRequests(), 100);
84
88
  try {
@@ -94,7 +98,8 @@ class GrpcPooledListener {
94
98
  if (Object.keys(this.subscribers).length === 0) {
95
99
  // FIXME it would be better to cleanup on parent complete
96
100
  this.client.logger.debug('All subscriptions finished, cleaning up listener');
97
- break;
101
+ this.signal.abort();
102
+ this.onFinish();
98
103
  }
99
104
  }
100
105
  }
@@ -107,16 +112,23 @@ class GrpcPooledListener {
107
112
  }
108
113
  finally { if (e_1) throw e_1.error; }
109
114
  }
115
+ this.client.logger.debug('Child listener finished');
110
116
  }
111
117
  catch (e) {
112
- if (!(0, abort_controller_x_1.isAbortError)(e)) {
113
- this.client.logger.error(`Error in child-listener: ${e.message}`);
114
- this.init(retries + 1);
118
+ if ((0, abort_controller_x_1.isAbortError)(e)) {
119
+ this.client.logger.debug('Child Listener aborted');
115
120
  return;
116
121
  }
117
- this.client.logger.debug('Child Listener aborted');
122
+ this.client.logger.error(`Error in child-listener: ${e.message}`);
123
+ }
124
+ finally {
125
+ // it is possible the server hangs up early,
126
+ // restart the listener if we still have subscribers
127
+ this.client.logger.debug('Child listener finally');
128
+ if (Object.keys(this.subscribers).length !== 0) {
129
+ this.init(retries + 1);
130
+ }
118
131
  }
119
- this.onFinish();
120
132
  });
121
133
  }
122
134
  subscribe(request) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "0.15.1-alpha0",
3
+ "version": "0.15.1-alpha1",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [