This repository has been archived by the owner on Apr 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #317 from camunda-community-hub:fail-job-retries
fixes #316
- Loading branch information
Showing
5 changed files
with
194 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/__tests__/integration/Worker-Failure-Retries.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { ZBClient } from '../..' | ||
import { CreateProcessInstanceResponse } from '../../lib/interfaces-grpc-1.0' | ||
|
||
// const trace = <T>(res: T) => { | ||
// // tslint:disable-next-line: no-console | ||
// console.log(res) | ||
// return res | ||
// } | ||
process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE' | ||
jest.setTimeout(60000) | ||
|
||
let zbc: ZBClient | ||
let wf: CreateProcessInstanceResponse | undefined | ||
|
||
beforeEach(() => { | ||
zbc = new ZBClient() | ||
}) | ||
|
||
afterEach(async () => { | ||
try { | ||
if (wf?.processInstanceKey) { | ||
await zbc.cancelProcessInstance(wf.processInstanceKey) | ||
} | ||
} catch (e: any) { | ||
// console.log('Caught NOT FOUND') // @DEBUG | ||
} finally { | ||
await zbc.close() // Makes sure we don't forget to close connection | ||
} | ||
}) | ||
|
||
test('Decrements the retries count by default', () => | ||
new Promise(async done => { | ||
await zbc.deployProcess('./src/__tests__/testdata/Worker-Failure-Retries.bpmn') | ||
wf = await zbc.createProcessInstance('worker-failure-retries', { | ||
conditionVariable: true, | ||
}) | ||
let called = false | ||
|
||
const worker = zbc.createWorker({ | ||
taskType: 'service-task-worker-failure-retries', | ||
taskHandler: job => { | ||
if (!called) { | ||
expect(job.retries).toBe(100) | ||
called = true | ||
return job.fail('Some reason') | ||
} | ||
expect(job.retries).toBe(99) | ||
done(null) | ||
return job.complete().then(async res => { | ||
await worker.close() | ||
return res | ||
}) | ||
} | ||
}) | ||
}) | ||
) | ||
|
||
test('Set the retries to a specific number when provided with one via simple signature', () => | ||
new Promise(async done => { | ||
await zbc.deployProcess('./src/__tests__/testdata/Worker-Failure-Retries.bpmn') | ||
wf = await zbc.createProcessInstance('worker-failure-retries', { | ||
conditionVariable: true, | ||
}) | ||
let called = false | ||
|
||
const worker = zbc.createWorker({ | ||
taskType: 'service-task-worker-failure-retries', | ||
taskHandler: job => { | ||
if (!called) { | ||
expect(job.retries).toBe(100) | ||
called = true | ||
return job.fail('Some reason', 101) | ||
} | ||
expect(job.retries).toBe(101) | ||
done(null) | ||
return job.complete().then(async res => { | ||
await worker.close() | ||
return res | ||
}) | ||
} | ||
}) | ||
}) | ||
) | ||
|
||
test('Set the retries to a specific number when provided with one via object signature', () => | ||
new Promise(async done => { | ||
await zbc.deployProcess('./src/__tests__/testdata/Worker-Failure-Retries.bpmn') | ||
wf = await zbc.createProcessInstance('worker-failure-retries', { | ||
conditionVariable: true, | ||
}) | ||
let called = false | ||
|
||
const worker = zbc.createWorker({ | ||
taskType: 'service-task-worker-failure-retries', | ||
taskHandler: job => { | ||
if (!called) { | ||
expect(job.retries).toBe(100) | ||
called = true | ||
return job.fail({ errorMessage: 'Some reason', retries: 101}) | ||
} | ||
expect(job.retries).toBe(101) | ||
done(null) | ||
return job.complete().then(async res => { | ||
await worker.close() | ||
return res | ||
}) | ||
} | ||
}) | ||
}) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" id="Definitions_1vwghmj" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.10.0"> | ||
<bpmn:process id="worker-failure-retries" name="Worker Failure Retries" isExecutable="true"> | ||
<bpmn:startEvent id="StartEvent_1" name="Start "> | ||
<bpmn:outgoing>SequenceFlow_0fp53hs</bpmn:outgoing> | ||
</bpmn:startEvent> | ||
<bpmn:serviceTask id="ServiceTask_0g6tf5f" name="Say Hello World"> | ||
<bpmn:extensionElements> | ||
<zeebe:taskDefinition type="service-task-worker-failure-retries" retries="100" /> | ||
<zeebe:taskHeaders> | ||
<zeebe:header key="message" value="Hello World" /> | ||
</zeebe:taskHeaders> | ||
</bpmn:extensionElements> | ||
<bpmn:incoming>SequenceFlow_0fp53hs</bpmn:incoming> | ||
<bpmn:outgoing>SequenceFlow_112zghv</bpmn:outgoing> | ||
</bpmn:serviceTask> | ||
<bpmn:sequenceFlow id="SequenceFlow_0fp53hs" sourceRef="StartEvent_1" targetRef="ServiceTask_0g6tf5f" /> | ||
<bpmn:endEvent id="EndEvent_16r84dr" name="End"> | ||
<bpmn:incoming>SequenceFlow_112zghv</bpmn:incoming> | ||
</bpmn:endEvent> | ||
<bpmn:sequenceFlow id="SequenceFlow_112zghv" sourceRef="ServiceTask_0g6tf5f" targetRef="EndEvent_16r84dr" /> | ||
</bpmn:process> | ||
<bpmn:message id="Message_0remzna" name="Waiting For A Train That Never Arrives"> | ||
<bpmn:extensionElements> | ||
<zeebe:subscription correlationKey="=none" /> | ||
</bpmn:extensionElements> | ||
</bpmn:message> | ||
<bpmndi:BPMNDiagram id="BPMNDiagram_1"> | ||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="worker-failure-retries"> | ||
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1"> | ||
<dc:Bounds x="173" y="102" width="36" height="36" /> | ||
<bpmndi:BPMNLabel> | ||
<dc:Bounds x="179" y="145" width="24" height="40" /> | ||
</bpmndi:BPMNLabel> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNShape id="ServiceTask_0g6tf5f_di" bpmnElement="ServiceTask_0g6tf5f"> | ||
<dc:Bounds x="302" y="80" width="100" height="80" /> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNShape id="EndEvent_16r84dr_di" bpmnElement="EndEvent_16r84dr"> | ||
<dc:Bounds x="482" y="102" width="36" height="36" /> | ||
<bpmndi:BPMNLabel> | ||
<dc:Bounds x="490" y="145" width="20" height="14" /> | ||
</bpmndi:BPMNLabel> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNEdge id="SequenceFlow_0fp53hs_di" bpmnElement="SequenceFlow_0fp53hs"> | ||
<di:waypoint x="209" y="120" /> | ||
<di:waypoint x="302" y="120" /> | ||
</bpmndi:BPMNEdge> | ||
<bpmndi:BPMNEdge id="SequenceFlow_112zghv_di" bpmnElement="SequenceFlow_112zghv"> | ||
<di:waypoint x="402" y="120" /> | ||
<di:waypoint x="482" y="120" /> | ||
</bpmndi:BPMNEdge> | ||
</bpmndi:BPMNPlane> | ||
</bpmndi:BPMNDiagram> | ||
</bpmn:definitions> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters