-
Notifications
You must be signed in to change notification settings - Fork 263
/
DurableEntityStatus.cs
70 lines (63 loc) · 2.35 KB
/
DurableEntityStatus.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using System;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Microsoft.Azure.WebJobs.Extensions.DurableTask
{
/// <summary>
/// Represents the status of a durable entity instance.
/// </summary>
[DataContract]
public class DurableEntityStatus
{
internal DurableEntityStatus() { }
internal DurableEntityStatus(DurableOrchestrationStatus orchestrationStatus)
{
this.EntityId = EntityId.GetEntityIdFromSchedulerId(orchestrationStatus.InstanceId);
this.LastOperationTime = orchestrationStatus.LastUpdatedTime;
if (orchestrationStatus?.Input is JObject input)
{
SchedulerState state = input.ToObject<SchedulerState>();
if (state?.EntityState != null)
{
try
{
// Entity state is expected to be JSON-compatible
this.State = JToken.Parse(state.EntityState);
}
catch (JsonException)
{
// Just in case the above assumption is ever wrong, fallback to a raw string
this.State = state.EntityState;
}
}
}
}
/// <summary>
/// Gets the EntityId of the queried entity instance.
/// </summary>
/// <value>
/// The unique EntityId of the instance.
/// </value>
[DataMember(Name = "entityId")]
public EntityId EntityId { get; set; }
/// <summary>
/// Gets the time of the last operation processed by the entity instance.
/// </summary>
/// <value>
/// The last operation time in UTC.
/// </value>
[DataMember(Name = "lastOperationTime")]
public DateTime LastOperationTime { get; set; }
/// <summary>
/// Gets the state of the entity instance.
/// </summary>
/// <value>
/// The state as either a <c>JToken</c> or <c>null</c> if no state was provided.
/// </value>
[DataMember(Name = "state")]
public JToken State { get; set; }
}
}