• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lucaslorentz / durabletask-extensions / 9336995150

02 Jun 2024 08:43AM UTC coverage: 81.967% (+0.03%) from 81.942%
9336995150

push

github

lucaslorentz
Update to EF Core 8

6 of 6 new or added lines in 1 file covered. (100.0%)

2350 of 2867 relevant lines covered (81.97%)

139.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

19.64
/src/LLL.DurableTask.EFCore/Extensions/HistoryEventExtensions.cs
1
using System.Collections.Generic;
2
using System.Linq;
3
using DurableTask.Core;
4
using DurableTask.Core.History;
5
using DurableTask.Core.Serializing;
6

7
namespace LLL.DurableTask.EFCore.Extensions;
8

9
public static class HistoryEventExtensions
10
{
11
    public static int? GetTriggerEventId(this HistoryEvent historyEvent)
12
    {
13
        switch (historyEvent)
14
        {
15
            case TaskCompletedEvent taskCompletedEvent:
16
                return taskCompletedEvent.TaskScheduledId;
×
17
            case TaskFailedEvent taskFailedEvent:
18
                return taskFailedEvent.TaskScheduledId;
×
19
            case TimerFiredEvent timerFiredEvent:
20
                return timerFiredEvent.TimerId;
×
21
            case SubOrchestrationInstanceCompletedEvent subOrchestrationCreated:
22
                return subOrchestrationCreated.TaskScheduledId;
×
23
            case SubOrchestrationInstanceFailedEvent subOrchestrationFailed:
24
                return subOrchestrationFailed.TaskScheduledId;
×
25
        }
26
        return null;
×
27
    }
28

29
    public static IList<HistoryEvent> Reopen(this IList<HistoryEvent> historyEvents, DataConverter dataConverter)
30
    {
31
        return historyEvents
130✔
32
            .Select(e => e is ExecutionCompletedEvent completedEvent
154✔
33
                && completedEvent.OrchestrationStatus == OrchestrationStatus.Completed
154✔
34
                ? e.Rewind(dataConverter) : e)
154✔
35
            .ToArray();
130✔
36
    }
37

38
    public static RewindResult Rewind(this IList<HistoryEvent> historyEvents, HistoryEvent rewindPoint, string reason, DataConverter dataConverter)
39
    {
40
        var runtimeState = new OrchestrationRuntimeState(historyEvents);
×
41

42
        var eventsToKeep = historyEvents.TakeWhile(e => e != rewindPoint).ToArray();
×
43
        var eventsToRewind = historyEvents.SkipWhile(e => e != rewindPoint).ToArray();
×
44

45
        var result = new RewindResult();
×
46

47
        foreach (var eventToKeep in eventsToKeep)
×
48
        {
49
            result.HistoryEvents.Add(eventToKeep);
×
50

51
            var completionEventToRewind = eventsToRewind.FirstOrDefault(h => h.GetTriggerEventId() == eventToKeep.EventId);
×
52
            if (completionEventToRewind == null)
×
53
                continue;
54

55
            switch (eventToKeep)
56
            {
57
                case TaskScheduledEvent taskScheduledEvent:
58
                    {
59
                        result.OutboundMessages.Add(new TaskMessage
×
60
                        {
×
61
                            OrchestrationInstance = runtimeState.OrchestrationInstance,
×
62
                            Event = taskScheduledEvent,
×
63
                        });
×
64
                        break;
×
65
                    }
66
                case TimerCreatedEvent timerCreatedEvent:
67
                    {
68
                        result.TimerMessages.Add(new TaskMessage
×
69
                        {
×
70
                            OrchestrationInstance = runtimeState.OrchestrationInstance,
×
71
                            Event = completionEventToRewind
×
72
                        });
×
73
                        break;
×
74
                    }
75
                case SubOrchestrationInstanceCreatedEvent subOrchestrationCreatedEvent:
76
                    {
77
                        result.SubOrchestrationsInstancesToRewind.Add(subOrchestrationCreatedEvent.InstanceId);
×
78
                        break;
79
                    }
80
            }
81
        }
82

83
        foreach (var eventToRewind in eventsToRewind)
×
84
        {
85
            if (eventToRewind is OrchestratorStartedEvent || eventToRewind is OrchestratorCompletedEvent)
×
86
            {
87
                result.HistoryEvents.Add(eventToRewind);
×
88
            }
89
            else
90
            {
91
                var rewoundEvent = eventToRewind.Rewind(dataConverter);
×
92
                result.HistoryEvents.Add(rewoundEvent);
×
93
            }
94
        }
95

96
        result.OrchestratorMessages.Add(new TaskMessage
×
97
        {
×
98
            OrchestrationInstance = runtimeState.OrchestrationInstance,
×
99
            Event = new GenericEvent(-1, $"Rewind reason: {reason}")
×
100
        });
×
101

102
        result.NewRuntimeState = new OrchestrationRuntimeState(result.HistoryEvents);
×
103

104
        return result;
×
105
    }
106

107
    public static HistoryEvent Rewind(this HistoryEvent eventToRewind, DataConverter dataConverter)
108
    {
109
        var rewoundData = dataConverter.Serialize(eventToRewind);
6✔
110
        var genericEvent = new GenericEvent(eventToRewind.EventId, $"Rewound: {rewoundData}")
6✔
111
        {
6✔
112
            Timestamp = eventToRewind.Timestamp
6✔
113
        };
6✔
114
        return genericEvent;
6✔
115
    }
116
}
117

118
public class RewindResult
119
{
120
    public List<TaskMessage> OutboundMessages { get; } = new List<TaskMessage>();
×
121
    public List<TaskMessage> TimerMessages { get; } = new List<TaskMessage>();
×
122
    public List<TaskMessage> OrchestratorMessages { get; } = new List<TaskMessage>();
×
123
    public List<string> SubOrchestrationsInstancesToRewind { get; } = new List<string>();
×
124
    public List<HistoryEvent> HistoryEvents { get; } = new List<HistoryEvent>();
×
125
    public OrchestrationRuntimeState NewRuntimeState { get; set; }
×
126
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc