dhiaayachi / temporal

Temporal service
https://docs.temporal.io
MIT License
0 stars 0 forks source link

WorkflowContext provides whether the current workflow task is from a reset #150

Open dhiaayachi opened 2 months ago

dhiaayachi commented 2 months ago

Is your feature request related to a problem? Please describe.

It's not possible to know whether or not the current task is from a reset. It would be much simpler to build a logic in workflow to fail on certain case (to stop all the activities), then I will reset it later to resume.

Describe the solution you'd like

Expose a boolean flag in WorkflowContext to indicate whether the current workflow task is from a reset?(basically if the previous task is workflow task failed with reason of Reset)

dhiaayachi commented 1 month ago

This issue requests the ability to determine if a workflow task is part of a reset using a boolean flag within WorkflowContext. Currently, there's no way to directly check this within the workflow code.

Here's a breakdown of the issue and proposed solution:

Problem:

Proposed Solution:

Benefits:

Example:

// Within a workflow implementation
if (Workflow.getExecutionContext().isWorkflowTaskFromReset()) {
  // Logic specific to workflow tasks after a reset
  // ...
} else {
  // Logic for regular workflow tasks
  // ...
}

This feature would enhance workflow flexibility and simplify development by providing a direct mechanism to handle workflow reset scenarios.

Related Resources:

By implementing this feature, Temporal would provide developers with more control and clarity when handling workflow resets, leading to more robust and efficient workflow implementations.

dhiaayachi commented 1 month ago

Thank you for your feature request.

It's a great idea to be able to identify if a Workflow task is from a reset. This would indeed be very helpful for building more robust and flexible Workflows.

While we don't have this specific feature implemented right now, you could potentially achieve a similar effect using a custom state management mechanism within your Workflow. For example:

  1. Define a custom flag: Maintain a flag within your Workflow's state that indicates whether it's being run for the first time or after a reset.
  2. Update the flag on reset: When your Workflow is reset, update the flag to indicate that it is a reset scenario.
  3. Conditionally execute logic: Use the flag to determine which logic to execute based on whether it's a fresh start or a reset.

We understand the value of this feature and are considering it for future releases. Feel free to share your feedback and use case scenarios in our Support Forum, and we'll be sure to take them into consideration.

dhiaayachi commented 1 month ago

Thank you for the feature request. While this is a useful feature, it's not currently supported by the Temporal SDKs.

Here are a few ways to work around this for now:

We appreciate your feedback and will consider it for future enhancements to the Temporal SDKs.

dhiaayachi commented 1 month ago

Thank you for your feature request!

It would be helpful to have a boolean flag in the WorkflowContext indicating whether the current workflow task is from a reset.

Currently, there isn't a direct way to determine this using WorkflowContext, but you can achieve this using the Workflow.getExecutionInfo() method and comparing the RunId of the current workflow execution with the RunId of the previously completed workflow.

This will help you implement your desired logic for failing the workflow in certain cases and then resetting it.

dhiaayachi commented 1 month ago

Thank you for your feature request!

It's a great idea to know whether or not the current task is from a reset. It would allow developers to build more robust workflow logic by handling resets specifically.

While this feature isn't currently available, you can achieve a similar outcome by incorporating custom logic into your workflow. Here's a possible workaround:

  1. Implement a custom state variable: Introduce a state variable (e.g., isReset) within your workflow. Initialize it to false at the start.
  2. Update the state on reset: When a workflow is reset, update the isReset state variable to true. You can achieve this within the workflow definition itself or using the Temporal CLI command temporal workflow reset.
  3. Check the state in workflow logic: In your workflow logic, use the isReset state variable to determine whether the current execution is a result of a reset.
  4. Take appropriate actions: Based on the value of isReset, implement logic to handle the reset scenario. This might involve skipping certain activities or performing specific tasks related to the reset.

This approach provides you with the flexibility to implement custom handling for reset scenarios within your workflow.

Let us know if you have any other questions.

dhiaayachi commented 1 month ago

Thanks for the feature request! Currently, there is no way to identify whether a workflow task is from a reset. We understand that this information would be useful for workflow logic, especially when it comes to failures and restarts.

A possible workaround for your use case would be to use a custom flag in your workflow state. You could set this flag when you initiate a reset, and then check it in your workflow logic. This would allow you to tailor your workflow behavior based on whether a reset has occurred.

We will consider adding a flag like the one you suggested to WorkflowContext for a future release.