Skip to content

feat: handle zeebe task retries #880

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
16 changes: 15 additions & 1 deletion src/provider/cloud-element-templates/CreateHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ export function createTaskDefinitionWithType(value, bpmnFactory) {
});
}

/**
* Create a task definition representing the given value.
*
* @param {String} value
* @param {BpmnFactory} bpmnFactory
*
* @return {ModdleElement}
*/
export function createTaskDefinitionWithRetries(value, bpmnFactory) {
return bpmnFactory.create('zeebe:TaskDefinition', {
retries: value
});
}

/**
* Create zeebe:Property from the given binding.
*
Expand Down Expand Up @@ -136,4 +150,4 @@ export function ensureExtension(element, type, bpmnFactory) {
}

return extension;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import {
createInputParameter,
createOutputParameter,
createTaskDefinitionWithRetries,
createTaskDefinitionWithType,
createTaskHeader,
createZeebeProperty,
Expand Down Expand Up @@ -206,14 +207,18 @@ export default class ChangeElementTemplateHandler {

if (!shouldKeepValue(oldTaskDefinition, oldProperty, newProperty)) {

// TODO(pinussilvestrus): for now we only support <type>
// TODO(pinussilvestrus): for now we only support <type> and <retries>
// this needs to be adjusted once we support more
let properties = {};

if (oldBindingType === 'zeebe:taskDefinition:type' || !oldBindingType) {
properties = {
type: newPropertyValue
};
} else if (oldBindingType === 'zeebe:taskDefinition:retries' || !oldBindingType) {
properties = {
retries: newPropertyValue
};
}

commandStack.execute('element.updateModdleProperties', {
Expand All @@ -228,10 +233,12 @@ export default class ChangeElementTemplateHandler {
else {
let newTaskDefinition;

// TODO(pinussilvestrus): for now we only support <type>
// TODO(pinussilvestrus): for now we only support <type> and <retries>
// this needs to be adjusted once we support more
if (newBindingType === 'zeebe:taskDefinition:type') {
newTaskDefinition = createTaskDefinitionWithType(newPropertyValue, bpmnFactory);
} else if (newBindingType === 'zeebe:taskDefinition:retries') {
newTaskDefinition = createTaskDefinitionWithRetries(newPropertyValue, bpmnFactory);
}

commandStack.execute('element.updateModdleProperties', {
Expand Down Expand Up @@ -891,4 +898,4 @@ function remove(array, item) {
array.splice(index, 1);

return array;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { getBusinessObject } from 'bpmn-js/lib/util/ModelUtil';

import { createTaskDefinitionWithRetries } from '../CreateHelper';


export default class TaskDefinitionRetriesBindingProvider {
static create(element, options) {
const {
property,
bpmnFactory
} = options;

const {
value
} = property;

const extensionElements = getBusinessObject(element).get('extensionElements');

const taskDefinition = createTaskDefinitionWithRetries(value, bpmnFactory);
taskDefinition.$parent = extensionElements;
extensionElements.get('values').push(taskDefinition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { find } from 'min-dash';
import validate from '../util/validate';

import PropertyBindingProvider from './PropertyBindingProvider';
import TaskDefinitionRetriesBindingProvider from './TaskDefinitionRetriesBindingProvider';
import TaskDefinitionTypeBindingProvider from './TaskDefinitionTypeBindingProvider';
import InputBindingProvider from './InputBindingProvider';
import OutputBindingProvider from './OutputBindingProvider';
Expand All @@ -16,6 +17,7 @@ import ZeebePropertiesProvider from './ZeebePropertiesProvider';
import {
EXTENSION_BINDING_TYPES,
PROPERTY_TYPE,
ZEEBE_TASK_DEFINITION_RETRIES_TYPE,
ZEEBE_TASK_DEFINITION_TYPE_TYPE,
ZEBBE_INPUT_TYPE,
ZEEBE_OUTPUT_TYPE,
Expand All @@ -34,6 +36,7 @@ export default class TemplateElementFactory {

this._providers = {
[PROPERTY_TYPE]: PropertyBindingProvider,
[ZEEBE_TASK_DEFINITION_RETRIES_TYPE]: TaskDefinitionRetriesBindingProvider,
[ZEEBE_TASK_DEFINITION_TYPE_TYPE]: TaskDefinitionTypeBindingProvider,
[ZEBBE_PROPERTY_TYPE]: ZeebePropertiesProvider,
[ZEBBE_INPUT_TYPE]: InputBindingProvider,
Expand Down Expand Up @@ -185,4 +188,4 @@ function hasIcon(template) {
} = template;

return !!(icon && icon.contents);
}
}
5 changes: 4 additions & 1 deletion src/provider/cloud-element-templates/util/bindingTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@ export const ZEBBE_PROPERTY_TYPE = 'zeebe:property';
export const ZEBBE_INPUT_TYPE = 'zeebe:input';
export const ZEEBE_OUTPUT_TYPE = 'zeebe:output';
export const ZEEBE_PROPERTY_TYPE = 'zeebe:property';
export const ZEEBE_TASK_DEFINITION_RETRIES_TYPE = 'zeebe:taskDefinition:retries';
export const ZEEBE_TASK_DEFINITION_TYPE_TYPE = 'zeebe:taskDefinition:type';
export const ZEEBE_TASK_HEADER_TYPE = 'zeebe:taskHeader';

export const EXTENSION_BINDING_TYPES = [
ZEBBE_INPUT_TYPE,
ZEEBE_OUTPUT_TYPE,
ZEEBE_PROPERTY_TYPE,
ZEEBE_TASK_DEFINITION_RETRIES_TYPE,
ZEEBE_TASK_DEFINITION_TYPE_TYPE,
ZEEBE_TASK_HEADER_TYPE
];

export const TASK_DEFINITION_TYPES = [
ZEEBE_TASK_DEFINITION_RETRIES_TYPE,
ZEEBE_TASK_DEFINITION_TYPE_TYPE
];

export const IO_BINDING_TYPES = [
ZEBBE_INPUT_TYPE,
ZEEBE_OUTPUT_TYPE
];
];
6 changes: 4 additions & 2 deletions src/provider/cloud-element-templates/util/propertyUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
ZEBBE_INPUT_TYPE,
ZEEBE_OUTPUT_TYPE,
ZEEBE_PROPERTY_TYPE,
ZEEBE_TASK_HEADER_TYPE
ZEEBE_TASK_HEADER_TYPE, ZEEBE_TASK_DEFINITION_RETRIES_TYPE
} from '../util/bindingTypes';

import {
Expand All @@ -26,7 +26,7 @@ import {

import {
createInputParameter,
createOutputParameter,
createOutputParameter, createTaskDefinitionWithRetries,
createTaskDefinitionWithType,
createTaskHeader,
createZeebeProperty,
Expand Down Expand Up @@ -251,6 +251,8 @@ export function setPropertyValue(bpmnFactory, commandStack, element, property, v

if (type === ZEEBE_TASK_DEFINITION_TYPE_TYPE) {
newTaskDefinition = createTaskDefinitionWithType(value, bpmnFactory);
} else if (type === ZEEBE_TASK_DEFINITION_RETRIES_TYPE) {
newTaskDefinition = createTaskDefinitionWithRetries(value, bpmnFactory);
} else {
throw unknownBindingError(element, property);
}
Expand Down
11 changes: 9 additions & 2 deletions test/spec/provider/cloud-element-templates/fixtures/complex.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,19 @@
"entriesVisible": true,
"properties": [
{
"type": "Hidden",
"type": "String",
"value": "http",
"binding": {
"type": "zeebe:taskDefinition:type"
}
},
{
"type": "String",
"value": "5",
"binding": {
"type": "zeebe:taskDefinition:retries"
}
},
{
"label": "REST Endpoint URL",
"description": "Specify the url of the REST API to talk to.",
Expand Down Expand Up @@ -684,4 +691,4 @@
}
]
}
]
]