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

Update ContentUpdateTask, add SetCorrelationId function #10928

Merged
merged 23 commits into from
Apr 22, 2024

Conversation

hyzx86
Copy link
Contributor

@hyzx86 hyzx86 commented Dec 28, 2021

The correlationId with the workflow will be assigned after the content is created (step1)
but ,when a content item is created in a workflow using a Create Content Activity , the contentItemId of the new content overrides the correlationId of the workflow . ( step2)

Causes step3 and step4 never to trigger

image
in step 2

image

@hyzx86
Copy link
Contributor Author

hyzx86 commented Dec 29, 2021

Hi @Skrypt ,Can you help review this PR?

@hishamco hishamco requested a review from jtkech December 29, 2021 17:12
@Skrypt Skrypt self-requested a review December 30, 2021 20:17
@hyzx86
Copy link
Contributor Author

hyzx86 commented Feb 24, 2022

Hi @Skrypt Is there anything wrong with this change?

@hyzx86
Copy link
Contributor Author

hyzx86 commented Feb 25, 2022

@hishamco Done.

@hishamco
Copy link
Member

Why the build failed?

@hishamco
Copy link
Member

I re-run the jobs, the build is pass

@jtkech
Copy link
Member

jtkech commented Feb 25, 2022

Not sure I agree with this one, it fixes some scenarios but breaks other ones, e.g. after the execution of a RetrieveContentTask we may want (through the correlationId) to be in sync with the retrieved contentItemId even if an existing correlationId is already set. For other scenarios we have e.g. the Set Output and Set Property activities allowing to set and then retrieve a previous correlationId

For your scenario we have the oob User Task activity that halts the workflow until the user execute an action on a content item, in the activity settings you can define the action and the user role that can do the action, here the action could be named e.g. Approve, in that case if you edit the related content item you will see an Approve button that you will be able to click if you have the permission.

@hyzx86
Copy link
Contributor Author

hyzx86 commented Feb 26, 2022

Hi @jtkech

after the execution of a RetrieveContentTask we may want (through the correlationId) to be in sync with the retrieved contentItemId even if an existing correlationId is already set.

I think this operation is a little too subtle, and no one knows it without documentation and without looking at the code
As a workflow node, it should not affect the global properties of the entire workflow, it should only take the input and output the appropriate content, Unless it is the Task explicitly to update correlationId,
Otherwise, the global properties of the workflow should not be modified implicitly within it, And they're just a Task not an Event
we can get all the information through LastResult

In addition, the approval I refer to is not just approval through OC interface, if I want users to approve by email. Some dynamic scripts cannot be executed

@jtkech
Copy link
Member

jtkech commented Feb 26, 2022

@hyzx86

Yes I understand your use case ;) But still not sure that the correlationId should always stay the same for the whole WF execution, particularly after the retrieve content task, maybe an activity option to not override an existing correlationId.

Maybe here your signal_url would need to be correlated with the global WorkflowId, not the ContentItemId, hmm can be done by inserting between step 1 and 2 a correlate task that just set the correlationId to null, in that case I think that the signal_url token will use the workflowId instead.

Anyway I don't want to block your PR, so I will let others triage it.

@hyzx86
Copy link
Contributor Author

hyzx86 commented Feb 26, 2022

I remember that in the signal task if the corrlationID is empty, it creates a new ID instead of using the workflow ID directly.
The workflow ID may not exist because the signal task can also start the workflow (too long ago to remember).

This approval process is just an example.
If I need multiple levels of approval, I need to reset correlationid before each approval task.

@hishamco
Copy link
Member

@jtkech I will label this as dontmerge and let you decide how this should go, or let the others triage it

@jtkech
Copy link
Member

jtkech commented Feb 26, 2022

I remember that in the signal task if the corrlationID is empty, it creates a new ID instead of using the workflow ID directly.

There is no signal task, only a signal event, and we can generate a signal url through a SignalMethodProvider or a signal_url liquid filter (as here), that targets the HttpWorkflowController that will trigger the related workflow, in both ways to generate the url if CorrelationId is null or empty the WorkflowId is used in the payload.

The workflow ID may not exist because the signal task can also start the workflow

I don't think so, on each NewWorkflow() a new WorkflowId is generated.

Just tried to add just before step 2 a CorrelateTask with no value that I named "Decorrelate", yes when we edit the halted instance we still see the CorrelationId set to the 2nd contentItemId, but in the approval page the signal_url was already generated with the WorkflowId, then when I clicked on an Approve/Reject link the WF was resumed.

@Piedone
Copy link
Member

Piedone commented Jan 28, 2024

Is this something you'd like to revisit any time soon @hyzx86 or should we close?

@hyzx86
Copy link
Contributor Author

hyzx86 commented Jan 29, 2024

Is this something you'd like to revisit any time soon @hyzx86 or should we close?

Hi @Piedone , Combined with the problems mentioned by JT, I don't think there will be any problems with my PR

The existing code will always update CorrelationId, I'm just adding a check

@Piedone
Copy link
Member

Piedone commented Jan 29, 2024

OK then! @hishamco @Skrypt you've reviewed this previously, please check this out if you still approve. Also, Hisham you added dontmerge, please check that's still applicable.

@Skrypt
Copy link
Contributor

Skrypt commented Jan 30, 2024

You can always still update the correlationId by using different methods as mentioned by @hyzx86 and J-T. Maybe it can potentially break someone's workflow but that's how it is when you do a change in these ... document the change in the release notes.

@hyzx86
Copy link
Contributor Author

hyzx86 commented Jan 31, 2024

@Skrypt , Maybe I can add a script function to this PR
Just like setCorrelationId(string) ?

@Skrypt
Copy link
Contributor

Skrypt commented Jan 31, 2024

Yeah, maybe instead of setting it from server side we could have a script that would affect it. That would be non-breaking.

@hyzx86 hyzx86 marked this pull request as ready for review March 14, 2024 03:58
@hyzx86 hyzx86 requested review from Skrypt and hishamco March 14, 2024 03:58
@hyzx86 hyzx86 changed the title Fix the BUG that CorrelationId is overwritten Update CotentUpdateTask ,add SetCorrelationId function Mar 14, 2024
Now, the CorrelationId value will only be updated if the current workflow's CorrelationId is empty.

Also added a workflow-scoped script function `setCorrelationId(id:string): void`, that you can use to update the workflow's CorrelationId.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe a friend who is good at English can help me adjust this text.

@agriffard agriffard changed the title Update CotentUpdateTask ,add SetCorrelationId function Update ContentUpdateTask ,add SetCorrelationId function Mar 20, 2024
@Piedone Piedone changed the title Update ContentUpdateTask ,add SetCorrelationId function Update ContentUpdateTask,add SetCorrelationId function Apr 6, 2024
@Piedone Piedone changed the title Update ContentUpdateTask,add SetCorrelationId function Update ContentUpdateTask, add SetCorrelationId function Apr 6, 2024
@Piedone
Copy link
Member

Piedone commented Apr 21, 2024

@Skrypt can you please elaborate on why do you think this needs triage? What should we be mindful of during the triage?

@Skrypt
Copy link
Contributor

Skrypt commented Apr 22, 2024

Waiting on @hyzx86 to know if he implemented what I suggested. If it is done then we need to review/test that code again to make sure it is fine.

It can be triaged on next thursday meeting and decided if it will be merged for current release or not.

@Piedone
Copy link
Member

Piedone commented Apr 22, 2024

Since this is a non-breaking change (right?) why wouldn't we merge if it otherwise looks good?

@Skrypt
Copy link
Contributor

Skrypt commented Apr 22, 2024

Yeah, he seems to have added the method. I'd say, let's merge it.

@Piedone
Copy link
Member

Piedone commented Apr 22, 2024

OK, please approve, and you @hishamco (since you reviewed previously).

@hishamco hishamco merged commit 3b4866e into OrchardCMS:main Apr 22, 2024
5 checks passed
@hyzx86 hyzx86 deleted the Fix_CorrelationID branch June 13, 2024 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants