diff --git a/.gitignore b/.gitignore
index 7ffd2300..b60c7bd7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,4 +6,5 @@ docs
cctest.ts
t.ts
yolo.bpmn
-crash-*.log
\ No newline at end of file
+crash-*.log
+camunda-cloud.env
\ No newline at end of file
diff --git a/example/start-workflow-instance.js b/example/start-workflow-instance.js
index e620004e..3cf824f9 100644
--- a/example/start-workflow-instance.js
+++ b/example/start-workflow-instance.js
@@ -1,11 +1,12 @@
// const ZB = require('zeebe-node');
-const ZB = require('../dist');
+const ZB = require('../dist')
-const jobs =
- (async () => {
- const zbc = new ZB.ZBClient("localhost:26500");
- for (let i = 0; i < 10; i++) {
- const result = await zbc.createWorkflowInstance("test-process", { testData: "something" });
- console.log(result);
- }
- })();
\ No newline at end of file
+const jobs = (async () => {
+ const zbc = new ZB.ZBClient()
+ for (let i = 0; i < 10; i++) {
+ const result = await zbc.createWorkflowInstance('test-process', {
+ testData: 'something',
+ })
+ console.log(result)
+ }
+})()
diff --git a/example/test.bpmn b/example/test.bpmn
index 1de16356..6916c100 100644
--- a/example/test.bpmn
+++ b/example/test.bpmn
@@ -1,134 +1,134 @@
-
-
-
-
- SequenceFlow_0flmcpy
-
-
-
-
-
- SequenceFlow_0flmcpy
- SequenceFlow_1a37fnv
-
-
-
-
- SequenceFlow_1a37fnv
- SequenceFlow_0813z63
- SequenceFlow_07t613r
-
-
- SequenceFlow_0813z63
- SequenceFlow_0dssivi
-
- PT5S
-
-
-
-
- SequenceFlow_07t613r
- SequenceFlow_02mvz0a
-
-
-
-
- SequenceFlow_1248rhd
- SequenceFlow_12mv0rh
-
-
-
-
-
- SequenceFlow_0dssivi
- SequenceFlow_1248rhd
-
-
-
-
-
-
-
- SequenceFlow_02mvz0a
- SequenceFlow_12mv0rh
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+
+
+
+
+ SequenceFlow_0flmcpy
+
+
+
+
+
+ SequenceFlow_0flmcpy
+ SequenceFlow_1a37fnv
+
+
+
+
+ SequenceFlow_1a37fnv
+ SequenceFlow_0813z63
+ SequenceFlow_07t613r
+
+
+ SequenceFlow_0813z63
+ SequenceFlow_0dssivi
+
+ PT5S
+
+
+
+
+ SequenceFlow_07t613r
+ SequenceFlow_02mvz0a
+
+
+
+
+ SequenceFlow_1248rhd
+ SequenceFlow_12mv0rh
+
+
+
+
+
+ SequenceFlow_0dssivi
+ SequenceFlow_1248rhd
+
+
+
+
+
+
+
+ SequenceFlow_02mvz0a
+ SequenceFlow_12mv0rh
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/example/workflows.js b/example/workflows.js
index d11c9a9f..36e072b4 100644
--- a/example/workflows.js
+++ b/example/workflows.js
@@ -2,16 +2,13 @@
const ZB = require('../dist')
;(async () => {
- const zbc = new ZB.ZBClient()
-
+ const zbc = new ZB.ZBClient({
+ onConnectionError: err => console.log('err', err),
+ onReady: () => console.log('YOO'),
+ })
const topology = await zbc.topology()
console.log(JSON.stringify(topology, null, 2))
- let workflows = await zbc.listWorkflows()
- console.log(workflows)
-
- await zbc.deployWorkflow('./test.bpmn')
-
- workflows = await zbc.listWorkflows()
- console.log(workflows)
+ const res = await zbc.deployWorkflow('./test.bpmn')
+ setTimeout(() => console.log(res), 5000)
})()
diff --git a/src/__tests__/integration/Worker-onReady.spec.ts b/src/__tests__/integration/Worker-onReady.spec.ts
index 3c58a8d5..04f1d99a 100644
--- a/src/__tests__/integration/Worker-onReady.spec.ts
+++ b/src/__tests__/integration/Worker-onReady.spec.ts
@@ -3,24 +3,19 @@ import { ZBClient } from '../..'
jest.setTimeout(30000)
process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'
-test(`Does call the onReady handler if there is a broker`, done => {
+test(`Worker calls the onReady handler if there is a broker`, done => {
let called = 0
const zbc2 = new ZBClient()
- zbc2.createWorker(
- null,
- 'nonsense-task',
- (_, complete) => complete.success,
- {
- onReady: () => {
- called++
- },
- }
- )
+ zbc2.createWorker('nonsense-task', (_, complete) => complete.success, {
+ onReady: () => {
+ called++
+ },
+ })
setTimeout(async () => {
expect(called).toBe(1)
await zbc2.close()
done()
- }, 6000)
+ }, 10000)
})
test(`Does set connected: true if there is a broker and eagerConnection: true`, done => {
@@ -31,7 +26,7 @@ test(`Does set connected: true if there is a broker and eagerConnection: true`,
expect(zbc2.connected).toBe(true)
await zbc2.close()
done()
- }, 6000)
+ }, 7000)
})
test(`Does not set connected: true if there is a broker and eagerConnection: false`, done => {
@@ -40,7 +35,7 @@ test(`Does not set connected: true if there is a broker and eagerConnection: fal
expect(zbc2.connected).toBe(undefined)
await zbc2.close()
done()
- }, 6000)
+ }, 7000)
})
test(`Does emit the ready event if there is a broker`, done => {
diff --git a/src/__tests__/local-integration/OnConnectionError.spec.ts b/src/__tests__/local-integration/OnConnectionError.spec.ts
index 05b4a91b..fa3db23f 100644
--- a/src/__tests__/local-integration/OnConnectionError.spec.ts
+++ b/src/__tests__/local-integration/OnConnectionError.spec.ts
@@ -4,65 +4,69 @@ jest.setTimeout(16000)
process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'
test(`Calls the onConnectionError handler if there is no broker and eagerConnection:true`, async done => {
- let called = 0
+ let calledA = 0
const zbc2 = new ZBClient('localtoast: 267890', {
eagerConnection: true,
onConnectionError: () => {
- called++
+ calledA++
},
})
setTimeout(async () => {
- expect(called).toBe(1)
+ expect(calledA).toBe(1)
await zbc2.close()
done()
}, 5000)
})
test(`Does not call the onConnectionError handler if there is a broker`, async done => {
- let called = 0
+ let calledB = 0
const zbc2 = new ZBClient({
onConnectionError: () => {
- called++
+ // tslint:disable-next-line: no-debugger
+ debugger
+ calledB++
+ // tslint:disable-next-line: no-console
+ console.log('ERROR')
},
})
setTimeout(async () => {
- expect(called).toBe(0)
+ expect(calledB).toBe(0)
await zbc2.close()
done()
}, 5000)
})
test(`Calls ZBClient onConnectionError once when there is no broker, eagerConnection:true, and workers with no handler`, async done => {
- let called = 0
+ let calledC = 0
const zbc2 = new ZBClient('localtoast:234532534', {
eagerConnection: true,
onConnectionError: () => {
- called++
+ calledC++
},
})
zbc2.createWorker(null, 'whatever', (_, complete) => complete.success)
zbc2.createWorker(null, 'whatever', (_, complete) => complete.success)
setTimeout(() => {
zbc2.close()
- expect(called).toBe(1)
+ expect(calledC).toBe(1)
done()
}, 10000)
})
test(`Calls ZBClient onConnectionError when there no broker, for the client and each worker with a handler`, async done => {
- let called = 0
+ let calledD = 0
const zbc2 = new ZBClient('localtoast:234532534', {
onConnectionError: () => {
- called++
+ calledD++
},
})
zbc2.createWorker('whatever', (_, complete) => complete.success, {
- onConnectionError: () => called++,
+ onConnectionError: () => calledD++,
})
// @TOFIX - debouncing
setTimeout(() => {
zbc2.close()
- expect(called).toBe(4) // Should be 2 if it is debounced
+ expect(calledD).toBe(4) // Should be 2 if it is debounced
done()
}, 10000)
})
@@ -86,25 +90,25 @@ test(`Debounces onConnectionError`, async done => {
})
test(`Trailing parameter worker onConnectionError handler API works`, async done => {
- let called = 0
+ let calledE = 0
const zbc2 = new ZBClient('localtoast:234532534', {})
zbc2.createWorker('whatever', (_, complete) => complete.success, {
- onConnectionError: () => called++,
+ onConnectionError: () => calledE++,
})
// @TOFIX - debouncing
setTimeout(async () => {
await zbc2.close()
- expect(called).toBe(4) // should be 1 if debounced
+ expect(calledE).toBe(4) // should be 1 if debounced
done()
}, 10000)
})
test(`Does not call the onConnectionError handler if there is a business error`, async done => {
- let called = 0
+ let calledF = 0
let wf = 'arstsrasrateiuhrastulyharsntharsie'
const zbc2 = new ZBClient({
onConnectionError: () => {
- called++
+ calledF++
},
})
zbc2.createWorkflowInstance(wf, {}).catch(() => {
@@ -112,7 +116,7 @@ test(`Does not call the onConnectionError handler if there is a business error`,
})
setTimeout(async () => {
expect(zbc2.connected).toBe(true)
- expect(called).toBe(0)
+ expect(calledF).toBe(0)
await zbc2.close()
done()
}, 10000)
diff --git a/src/lib/ConnectionFactory.ts b/src/lib/ConnectionFactory.ts
index 26fd44a7..ad28477f 100644
--- a/src/lib/ConnectionFactory.ts
+++ b/src/lib/ConnectionFactory.ts
@@ -15,7 +15,7 @@ export const ConnectionCharacteristics: {
CAMUNDA_CLOUD: {
_tag: 'CAMUNDA_CLOUD',
startupTime: parseInt(
- process.env.ZEEBE_INITIAL_CONNECTION_TOLERANCE || '5000',
+ process.env.ZEEBE_INITIAL_CONNECTION_TOLERANCE || '6000',
10
),
},
@@ -28,7 +28,7 @@ export const ConnectionCharacteristics: {
},
}
-export type State = 'ERROR' | 'CONNECTED'
+export type State = 'ERROR' | 'CONNECTED' | 'UNKNOWN'
export class ConnectionFactory {
public static getGrpcClient({
diff --git a/src/lib/GrpcMiddleware.ts b/src/lib/GrpcMiddleware.ts
index 560ce054..9b090e59 100644
--- a/src/lib/GrpcMiddleware.ts
+++ b/src/lib/GrpcMiddleware.ts
@@ -21,7 +21,7 @@ export class GrpcMiddleware {
}) {
this.characteristics = characteristics
this.blocking = this.characteristics.startupTime > 0
- this.state = this.blocking ? 'ERROR' : 'CONNECTED'
+ this.state = 'UNKNOWN'
log.logDebug(`Grpc Middleware blocking: ${this.blocking}`)
if (this.blocking) {
setTimeout(() => {
@@ -29,8 +29,10 @@ export class GrpcMiddleware {
log.logDebug(`Grpc Middleware state: ${this.state}`)
if (this.state === 'ERROR') {
this.emitError()
- } else {
+ } else if (this.state === 'CONNECTED') {
this.emitReady()
+ } else if (this.state === 'UNKNOWN') {
+ this.grpcClient.emit(ConnectionStatusEvent.Unknown)
}
}, this.characteristics.startupTime)
}
diff --git a/src/lib/ZBWorkerBase.ts b/src/lib/ZBWorkerBase.ts
index 3f06479f..ced93874 100644
--- a/src/lib/ZBWorkerBase.ts
+++ b/src/lib/ZBWorkerBase.ts
@@ -163,6 +163,7 @@ export class ZBWorkerBase<
this.connected = true
}
}
+ this.grpcClient.on(ConnectionStatusEvent.Unknown, onReady)
this.grpcClient.on(ConnectionStatusEvent.Ready, onReady)
this.cancelWorkflowOnException =
options.failWorkflowOnException || false
diff --git a/src/zb/ZBClient.ts b/src/zb/ZBClient.ts
index af65fbe4..4452718b 100644
--- a/src/zb/ZBClient.ts
+++ b/src/zb/ZBClient.ts
@@ -52,6 +52,7 @@ const idColors = [
export const ConnectionStatusEvent = {
ConnectionError: 'connectionError' as 'connectionError',
Ready: 'ready' as 'ready',
+ Unknown: 'unknown' as 'unknown',
}
export class ZBClient extends EventEmitter {