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

Example for tasks interaction #567

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

antmendoza
Copy link
Member

What was changed

Why?

Some users look into Temporal as an alternative to BPM tools, like jBPM or Camunda. One common question is how to deal with HumanTask. This example shows a basic implementation to track task state

Checklist

  1. Closes

  2. How was this tested:

  1. Any docs updates needed?

@antmendoza antmendoza requested review from tsurdilo and a team as code owners December 26, 2023 10:03
@tsurdilo
Copy link
Contributor

hey, sorry still reviewing. ty for doing this sample!

@antmendoza
Copy link
Member Author

no hurry @tsurdilo

import io.temporal.serviceclient.WorkflowServiceStubs;
import java.util.Arrays;
import java.util.List;

Copy link
Member

Choose a reason for hiding this comment

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

I think it is confusing to require WorkflowID to complete tasks as they are usually stored in a separate system.
The task token contains the workflow ID already. So I would change the TaskActivityImpl to print the task token and then the UpdateTask to get the token as an argument. The UpdateTask would parse out the workflow id out of the token and signal the appropriate workflow.

Copy link
Member Author

@antmendoza antmendoza Jan 3, 2024

Choose a reason for hiding this comment

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

import io.temporal.serviceclient.WorkflowServiceStubs;
import java.util.List;

public class ListOpenTasks {
Copy link
Member

Choose a reason for hiding this comment

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

I think this is confusing as this list tasks of a specific workflow. In real systems tasks assigned to a specific user would be listed. I would remove the whole list-related functionality to avoid such confusion.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, but also I think it could be useful to show the workflow execution internal state. Do you think we can expose this information in any other way or should I just remove it?

Copy link
Member Author

Choose a reason for hiding this comment

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

ListOpenTasks removed,

I am maintaining the method getOpenTask to query the internal state and complete the task automatically from UpdateTask

I can remove the method getOpenTask, and have the dev running the example passing the task id to UpdateTask , instead of getting the taskid from the workflow execution using getOpenTask

@tsurdilo
Copy link
Contributor

hi, is there any outstanding things to be done on this pr? thanks

@antmendoza
Copy link
Member Author

Hi @tsurdilo this is on me, I have to remove the getOpenTask method

@antmendoza antmendoza marked this pull request as draft March 20, 2024 16:42
antmendoza and others added 16 commits April 30, 2024 08:00
Bumps [org.mockito:mockito-core](https://github.com/mockito/mockito) from 5.8.0 to 5.11.0.
- [Release notes](https://github.com/mockito/mockito/releases)
- [Commits](mockito/mockito@v5.8.0...v5.11.0)

---
updated-dependencies:
- dependency-name: org.mockito:mockito-core
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [ch.qos.logback:logback-classic](https://github.com/qos-ch/logback) from 1.5.0 to 1.5.3.
- [Commits](qos-ch/logback@v_1.5.0...v_1.5.3)

---
updated-dependencies:
- dependency-name: ch.qos.logback:logback-classic
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…lio#601)

Bumps [com.fasterxml.jackson:jackson-bom](https://github.com/FasterXML/jackson-bom) from 2.16.1 to 2.17.0.
- [Commits](FasterXML/jackson-bom@jackson-bom-2.16.1...jackson-bom-2.17.0)

---
updated-dependencies:
- dependency-name: com.fasterxml.jackson:jackson-bom
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…mporalio#602)

Bumps [com.google.errorprone:error_prone_core](https://github.com/google/error-prone) from 2.25.0 to 2.26.1.
- [Release notes](https://github.com/google/error-prone/releases)
- [Commits](google/error-prone@v2.25.0...v2.26.1)

---
updated-dependencies:
- dependency-name: com.google.errorprone:error_prone_core
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Add KeyWordList type to typed SA sample

Signed-off-by: Tihomir Surdilovic <[email protected]>

* formatting

Signed-off-by: Tihomir Surdilovic <[email protected]>

---------

Signed-off-by: Tihomir Surdilovic <[email protected]>
@CLAassistant
Copy link

CLAassistant commented Apr 30, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ tsurdilo
❌ dependabot[bot]
You have signed the CLA already but the status is still pending? Let us recheck it.

@antmendoza antmendoza marked this pull request as ready for review April 30, 2024 06:16
@antmendoza
Copy link
Member Author

This is ready to review @mfateev @tsurdilo

I have created a new workflow that manages the task lifecycle with which the initial workflow interacts.

@joshmsmith
Copy link
Contributor

I like it, this is a nice sample to have.

@tsurdilo
Copy link
Contributor

Had a bit of a hard time following example code as in the whole time was thinking this would be good to have as a reusable interceptor that can be just applied to any workflow. Also would be nice to incorporate visibility into this as to
be able to know how many workflows are running that have pending tasks and at which stage of approval process they are.
wdyt?

@tsurdilo
Copy link
Contributor

Approving this as think its good sample, just see previous comment about it being bit hard to understand / follow.

@antmendoza
Copy link
Member Author

Thanks @tsurdilo

just see previous comment about it being bit hard to understand / follow.

Let me see if I can refactor it / make it simpler

Also would be nice to incorporate visibility into this as to
be able to know how many workflows are running that have pending tasks and at which stage of approval process they are.
wdyt?

👍

@antmendoza
Copy link
Member Author

antmendoza commented May 29, 2024

@tsurdilo I have refactored the code and added some comments

This is the commit b2a4f67

let me know if you find it easier to follow now
thanks

@antmendoza antmendoza requested a review from tsurdilo May 30, 2024 19:01
@antmendoza antmendoza requested review from tsurdilo and removed request for tsurdilo June 9, 2024 16:24

logger.info("Awaiting for the two tasks to complete");
// Block execution until both tasks complete
Promise.allOf(Arrays.asList(task1, task2)).get();
Copy link
Contributor

Choose a reason for hiding this comment

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

i think here you need to loop through promises again to check if any failed and if not call .get on each (to make sure they both actually compelted)

Copy link
Member Author

Choose a reason for hiding this comment

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

I get your point and i can add it, but I don't think any of these promises can fail with the current implementation

https://github.com/temporalio/samples-java/pull/567/files#diff-89e67e1da37a2cdfafecf424ebbae1cd65645bdf244e414e802dafd2fdf5208aR88


Thread.sleep(200);
final List<Task> pendingTask = getPendingTask(workflowTaskManager);
System.out.println("Pending task " + pendingTask);
Copy link
Contributor

Choose a reason for hiding this comment

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

do we want system outs here?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the client completing task , and this shows pending tasks.


initTaskList(inputPendingTasks);

Workflow.await(() -> Workflow.getInfo().isContinueAsNewSuggested());
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe im missing something here but if all tasks in task list complete
before continueAsNewSuggested triggers this exec will running

i wonder if this can be changed to like "if we did not receive any new tasks for duration X" maybe instead?
reason is that cost of running execs on cloud so users might wanna complete this exec and use signalWithStart instead when new tasks come in? maybe im missing something so let me know

Copy link
Member Author

Choose a reason for hiding this comment

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

I can add a condition so if there are no pending tasks the workflow returns/closes, WDYT @tsurdilo

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

Successfully merging this pull request may close these issues.

5 participants