-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSessionGrain.cs
More file actions
22 lines (19 loc) · 911 Bytes
/
SessionGrain.cs
File metadata and controls
22 lines (19 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using DotPilot.Core.Features.ControlPlaneDomain;
using DotPilot.Core.Features.RuntimeFoundation;
namespace DotPilot.Runtime.Host.Features.RuntimeFoundation;
public sealed class SessionGrain(
[PersistentState(EmbeddedRuntimeHostNames.SessionStateName, EmbeddedRuntimeHostNames.GrainStorageProviderName)]
IPersistentState<SessionDescriptor> sessionState) : Grain, ISessionGrain
{
public ValueTask<SessionDescriptor?> GetAsync()
{
return ValueTask.FromResult(sessionState.RecordExists ? sessionState.State : null);
}
public async ValueTask<SessionDescriptor> UpsertAsync(SessionDescriptor session)
{
EmbeddedRuntimeGrainGuards.EnsureMatchingKey(session.Id.ToString(), this.GetPrimaryKeyString(), EmbeddedRuntimeHostNames.SessionGrainName);
sessionState.State = session;
await sessionState.WriteStateAsync();
return sessionState.State;
}
}