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

add TaskDefinition Info for global service task handler #57

Closed
wants to merge 2 commits into from

Conversation

averyyan
Copy link
Contributor

i am try to use TaskDefinition info for automatic match grpc job service.
I want to replace AddTaskHandler to job service. I think id map is not enough.

@codecov
Copy link

codecov bot commented Sep 19, 2022

Codecov Report

Merging #57 (d77aa9f) into main (7d37aa7) will increase coverage by 0.18%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #57      +/-   ##
==========================================
+ Coverage   73.77%   73.95%   +0.18%     
==========================================
  Files          19       19              
  Lines         976      983       +7     
==========================================
+ Hits          720      727       +7     
  Misses        236      236              
  Partials       20       20              
Impacted Files Coverage Δ
pkg/bpmn_engine/engine_properties.go 20.00% <ø> (ø)
pkg/bpmn_engine/engine.go 89.96% <100.00%> (+0.10%) ⬆️
pkg/bpmn_engine/engine_jobs.go 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@nitram509
Copy link
Owner

Hi @averyyan
thank you for this PR.
I got your point, that adding Task-Handlers by ID is not ideal, and you're seeking for more global, or flexible way of defining Task Hnadlers.
I don't like the idea of a fixed serviceTaskHandler, as this bring some degree of flexibility, but usually, global definitions also have their down-sides.

What about "task type", see https://docs.camunda.io/docs/components/modeler/bpmn/service-tasks/
Also, please check the Camunda Modeller (model a v8 bpmn) and see how task type work.
This is something I would prefer to implement instead, since it would be more compatible with Zeebe and also gives more flexible way of defining a handler to one or multiple tasks - especially meaningful, when we later support sub-processes etc.

Would that task type work for your use case as well?

PS: when you consider refactoring your PR towards task type support - that would be awesome -
, please let us keep the existing approach.
I would prefer co-existence of addTaskHandlerForId() and addTaskHandlerForType().

@nitram509 nitram509 added the question Further information is requested label Sep 19, 2022
@averyyan
Copy link
Contributor Author

Hi @averyyan thank you for this PR. I got your point, that adding Task-Handlers by ID is not ideal, and you're seeking for more global, or flexible way of defining Task Hnadlers. I don't like the idea of a fixed serviceTaskHandler, as this bring some degree of flexibility, but usually, global definitions also have their down-sides.

What about "task type", see https://docs.camunda.io/docs/components/modeler/bpmn/service-tasks/ Also, please check the Camunda Modeller (model a v8 bpmn) and see how task type work. This is something I would prefer to implement instead, since it would be more compatible with Zeebe and also gives more flexible way of defining a handler to one or multiple tasks - especially meaningful, when we later support sub-processes etc.

Would that task type work for your use case as well?

PS: when you consider refactoring your PR towards task type support - that would be awesome - , please let us keep the existing approach. I would prefer co-existence of addTaskHandlerForId() and addTaskHandlerForType().

I just have this idea from https://docs.camunda.io/docs/components/modeler/bpmn/service-tasks/.
I think task definition is for definite kind of jobs.
I change this to addTaskHandlerForType() , it works too.
I use global fun because I have a problem to decide addTaskHandlerForId() ,addTaskHandlerForType() which one should be first :)

@@ -286,6 +287,11 @@ func checkOnlyOneAssociationOrPanic(event *BPMN20.BaseElement) {
}
}

// SetServiceTaskHandler set global service task handler to use task definition info
func (state *BpmnEngineState) SetServiceTaskHandler(handler func(job ActivatedJob)) {
Copy link
Owner

@nitram509 nitram509 Sep 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This func is not mentioned in the interface.
For completeness, it should be in the BpmnEngine interface

@@ -81,6 +82,11 @@ type TUserTask struct {
Output []TIoMapping `xml:"extensionElements>ioMapping>output"`
}

type TTaskDefinition struct {
TypeName string `xml:"type,attr"`
Retries string `xml:"retries,attr"`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since 'retries' is not used yet, I would prefer to not include it yet.

then.AssertThat(t, definition.Retries, is.EqualTo("testValue"))
}

func TestServiceTaskHandler(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that test is not easy to understand and lacks expressiveness, how service tasks are supposed to work.
I do suggest creating a dedicated .bpmn file to showcase service tasks

Copy link
Owner

@nitram509 nitram509 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
after carefully rethinking the overall approach of a single service handler, I would like to reject this PR. Multiple thoughts made me conclude this.
First, I was inspired by your idea. Also, I fully anticipate the use case you're describing.
In general, I prefer some degree of compatibility with Zeebe. While having a single global handler, which might fit your use case, others might want to use e.g. 3 handlers for 10 tasks. This is/was the reason, why Zeebe uses taskDefintion.Type to give flexibility in the assignments.
So, I thought a lot and had so many ideas for an alternative implementation, that I gave it a try on my own. For formal reasons, I also created a new issue #58 .

I would be glad if you could have a look at the implementation and check if it fits your use case, please. (I plan to push my code changes today)

@nitram509
Copy link
Owner

Not merged, in favor of 5303ef3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants