Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Mkatari3700
Copy link
Contributor

@Mkatari3700 Mkatari3700 commented Dec 21, 2023

Change Summary

  • Added async/Await in WorkOnce & ProcessTask Method
  • Execute method in IWorkFlowTask changed to Task (Async)
  • Updated the references where this IWorkFlowTask is being used
  • CancellationToken added at start so and checking all the places of nested method whether it is cancelled or not if yes then throw(OperationCancelledException) (when any unexpected exceptions happen we can utilize this and make CancellationToken.cancel so that it won't execute that particular task)
  • Added examples for single task executing and multi-task executing
  • Added Solution file also

This PR closes #86

{
var taskResult = _executeTaskMethod.Invoke(_workerInstance, new object[] { task });

if (token.IsCancellationRequested)
Copy link
Contributor

Choose a reason for hiding this comment

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

as a user how is the token used to send the request?

var taskResult = _executeTaskMethod.Invoke(_workerInstance, new object[] { task });

if (token.IsCancellationRequested)
return new TaskResult() { Status = TaskResult.StatusEnum.FAILEDWITHTERMINALERROR, ReasonForIncompletion = "Token Requested Cancel" };
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to extract more descriptive message?

throw new Exception("Token request Cancelled");
}

throw new Exception("random exception");
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is random exception here? Why do we need to throw exception here? Can we make the message proper?

throw new System.Exception("random exception");
if (token.IsCancellationRequested)
{
throw new Exception("Token request Cancelled");
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is token request cancellation? How it can be used from callee application side?

{
_workflowTaskMonitor.IncrementRunningWorker();
System.Threading.Tasks.Task.Run(() => ProcessTask(task));
threads.Add(Task.Run(() => ProcessTask(task)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if one thread takes longer duration to execute the task? Let say, there are 100 tasks. 99 completed within second but one task is stuck. Will this create any issues?

ProcessTasks(tasks);
var uniqueBatchId = Guid.NewGuid();
_logger.LogTrace(
$"[{_workerSettings.WorkerId}] Processing tasks batch"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need null check on workerSetting.workerId?

WorkflowTaskExecutorConfiguration WorkerSettings { get; }
TaskResult Execute(Task task);
Task<TaskResult> Execute(Models.Task task, CancellationToken token = default);
TaskResult Execute(Models.Task task);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you mark this as deprecated so its clear that the users should not use this going forward?
@BommannanRa

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes @v1r3n We have added deprecate message to the code. When someone try using Execute method, it would show message to move to ExecuteAsync (new implementation).

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @BommannanRa let's not change the method name as we want to keep the name consistent with the previous implementation ExecuteAsync should be just Execute

@v1r3n v1r3n merged commit 1484725 into conductor-oss:main Dec 29, 2023
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.

Async / Non blocking support

4 participants