Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(zeebe): activate jobs over REST #205

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# CAMUNDA_CONNECTORS_VERSION=0.23.2
CAMUNDA_CONNECTORS_VERSION=8.5.0
CAMUNDA_OPTIMIZE_VERSION=8.5.0
CAMUNDA_PLATFORM_VERSION=8.5.0
CAMUNDA_PLATFORM_VERSION=SNAPSHOT
CAMUNDA_WEB_MODELER_VERSION=8.5.0
ELASTIC_VERSION=8.9.0
KEYCLOAK_SERVER_VERSION=22.0.3
Expand Down
13 changes: 10 additions & 3 deletions src/__tests__/config/jest.cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,16 @@ export const cleanUp = async () => {
CAMUNDA_TENANT_ID: tenantId,
},
})
const res = await operate.searchProcessInstances({
filter: { bpmnProcessId: id, state: 'ACTIVE' },
})
const res = await operate
.searchProcessInstances({
filter: { bpmnProcessId: id, state: 'ACTIVE' },
})
.catch((e) => {
console.log(
`Failed to search for process instances for ${id} in tenant '${tenantId}'`
)
throw e
})
const instancesKeys = res.items.map((instance) => instance.key)
if (instancesKeys.length > 0) {
console.log(
Expand Down
48 changes: 48 additions & 0 deletions src/__tests__/testdata/rest-job-activation.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?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:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1m6sp12" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.25.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.5.0">
<bpmn:process id="rest-job-activation" name="Rest Job Activation" isExecutable="true">
<bpmn:startEvent id="StartEvent_1" name="Start REST Job Activation test">
<bpmn:outgoing>Flow_0fvlwwd</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_0fvlwwd" sourceRef="StartEvent_1" targetRef="Activity_196ccys" />
<bpmn:serviceTask id="Activity_196ccys" name="REST job">
<bpmn:extensionElements>
<zeebe:taskDefinition type="rest-job" />
</bpmn:extensionElements>
<bpmn:incoming>Flow_0fvlwwd</bpmn:incoming>
<bpmn:outgoing>Flow_06is06c</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:endEvent id="Event_0db85vg" name="REST Job Activation complete">
<bpmn:incoming>Flow_06is06c</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_06is06c" sourceRef="Activity_196ccys" targetRef="Event_0db85vg" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="rest-job-activation">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="159" y="142" width="77" height="27" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_13661gf_di" bpmnElement="Activity_196ccys">
<dc:Bounds x="270" y="77" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0db85vg_di" bpmnElement="Event_0db85vg">
<dc:Bounds x="432" y="99" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="425" y="142" width="50" height="40" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_0fvlwwd_di" bpmnElement="Flow_0fvlwwd">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_06is06c_di" bpmnElement="Flow_06is06c">
<di:waypoint x="370" y="117" />
<di:waypoint x="432" y="117" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
31 changes: 31 additions & 0 deletions src/__tests__/zeebe/integration-rest/ActivateJobs-rest.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ZeebeGrpcClient, ZeebeRestClient } from '../../../zeebe'

jest.setTimeout(30000)
test('can update a task', async () => {
const grpc = new ZeebeGrpcClient()

await grpc.deployResource({
processFilename: './src/__tests__/testdata/rest-job-activation.bpmn',
})
await grpc.createProcessInstance({
bpmnProcessId: 'rest-job-activation',
variables: {},
})

const zbc = new ZeebeRestClient()
const res = await zbc.activateJobs({
type: 'rest-job',
maxJobsToActivate: 100,
requestTimeout: 10,
timeout: 10,
worker: 'rest-worker',
})
console.log(res)
res.jobs.map((job) => {
grpc.completeJob({
jobKey: job.key,
variables: {},
})
})
expect(res.jobs.length > 0).toBe(true)
})
44 changes: 36 additions & 8 deletions src/zeebe/zb/ZeebeRESTClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import {
makeBeforeRetryHandlerFor401TokenRetry,
} from '../../lib'
import { IOAuthProvider } from '../../oauth'
import { TopologyResponse } from '../types'
import { ActivateJobsRequest, ActivatedJob, TopologyResponse } from '../types'

const trace = debug('camunda:zeebe')

const ZEEBE_REST_API_VERSION = 'v1'
const ZEEBE_REST_API_VERSION = 'v2'

/**
* JSON object with changed task attribute values.
Expand All @@ -39,6 +39,7 @@ export class ZeebeRestClient {
private userAgentString: string
private oAuthProvider: IOAuthProvider
private rest: Promise<typeof got>
private tenantId: string | undefined
// private tenantId: string | undefined

constructor(options?: {
Expand Down Expand Up @@ -80,7 +81,7 @@ export class ZeebeRestClient {
})
)

// this.tenantId = config.CAMUNDA_TENANT_ID
this.tenantId = config.CAMUNDA_TENANT_ID
}

private async getHeaders() {
Expand All @@ -96,6 +97,21 @@ export class ZeebeRestClient {
return headers
}

public async activateJobs(
req: ActivateJobsRequest
): Promise<{ jobs: ActivatedJob[] }> {
const headers = await this.getHeaders()
const tenantIds = req.tenantIds ?? this.tenantId ? [this.tenantId] : []
return this.rest.then((rest) =>
rest
.post('jobs/activation', {
headers,
body: JSON.stringify({ ...req, tenantIds }),
})
.json()
)
}

/* Get the topology of the Zeebe cluster. */
public async getTopology(): Promise<TopologyResponse> {
const headers = await this.getHeaders()
Expand All @@ -110,8 +126,10 @@ export class ZeebeRestClient {
) as Promise<TopologyResponse>
}

/* Completes a user task with the given key. The method either completes the task or throws 400, 404, or 409.
Documentation: https://docs.camunda.io/docs/apis-tools/zeebe-api-rest/specifications/complete-a-user-task/ */
/**
* Completes a user task with the given key. The method either completes the task or throws 400, 404, or 409.
* Documentation: https://docs.camunda.io/docs/apis-tools/zeebe-api-rest/specifications/complete-a-user-task/
* */
public async completeUserTask({
userTaskKey,
variables = {},
Expand All @@ -133,7 +151,10 @@ export class ZeebeRestClient {
)
}

/* Assigns a user task with the given key to the given assignee. */
/**
* Assigns a user task with the given key to the given assignee.
* Documentation: https://docs.camunda.io/docs/apis-tools/zeebe-api-rest/specifications/assign-a-user-task/
*/
public async assignTask({
userTaskKey,
assignee,
Expand All @@ -159,7 +180,10 @@ export class ZeebeRestClient {
)
}

/** Update a user task with the given key. */
/**
* Update a user task with the given key.
* Documenation: https://docs.camunda.io/docs/apis-tools/zeebe-api-rest/specifications/update-a-user-task/
*/
public async updateTask({
userTaskKey,
changeset,
Expand All @@ -176,7 +200,11 @@ export class ZeebeRestClient {
})
)
}
/* Removes the assignee of a task with the given key. */

/**
* Removes the assignee of a task with the given key.
* Documentation: https://docs.camunda.io/docs/apis-tools/zeebe-api-rest/specifications/unassign-a-user-task/
*/
public async removeAssignee({ userTaskKey }: { userTaskKey: string }) {
const headers = await this.getHeaders()

Expand Down
Loading