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

Allow GetWorkStatus to report NotStarted #56

Closed
hendrikdevloed opened this issue Feb 5, 2024 · 0 comments · Fixed by #57
Closed

Allow GetWorkStatus to report NotStarted #56

hendrikdevloed opened this issue Feb 5, 2024 · 0 comments · Fixed by #57

Comments

@hendrikdevloed
Copy link

GetWorkStatus() throws an exception when the grain has not been started yet, versus returning NotStarted.

if (_status == SyncWorkStatus.NotStarted)
{
    Logger.LogError("{Method} was in a status of {WorkStatus}", nameof(GetWorkStatus), SyncWorkStatus.NotStarted);
    DeactivateOnIdle();
    throw new InvalidStateException(_status);
}
return Task.FromResult(_status);

In my use case I intended to start a long-running task (in my project a sequenceFactoryGrain eventually creates a sequenceGrain, working as a long-running task) in an idempotent way, like

ISequenceGrain sequenceGrain = await sequenceFactoryGrain.GetWorkStatus() switch
{
    SyncWorkStatus.NotStarted => await sequenceFactoryGrain.StartWorkAndPollUntilResult(sequence),
    SyncWorkStatus.Running => await sequenceFactoryGrain.ContinueWorkAndPollUntilResult(sequence),
    SyncWorkStatus.Completed => (await sequenceFactoryGrain.GetResult())!,
    SyncWorkStatus.Faulted => throw (await sequenceFactoryGrain.GetException())!,
    _ => throw new NotImplementedException()
};

but was surprised by the exception thrown when trying to check the current state.

My intent: If some external non-Orleans API call tries to start the factory to get a grain, but if somehow there is a timeout/cancellation/... and the API retries, I should be able to find out that the sequenceFactoryGrain is already processing and just tag along waiting for the long-running call to complete.
(ContinueWorkAndPollUntilResult is the same code as StartWorkAndPollUntilResult but without the Start call)

Originally posted by @hendrikdevloed in #55 (comment)

I'll make the modification to allow retrieving GetWorkStatus() and set up a pull request.

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 a pull request may close this issue.

1 participant