Identify the first or last of a fact #331
-
Lets say you have a stream of events, and in that stream you will have multiple facts that will trigger the same rule. I have a stream of events and some events will trigger the same rules multiple times, adding similar facts multiple times. For instance, messages in a conversation. I thought I could do this with queries by specifying an order and then using LINQ How can I select the first or last of a set of facts? I thought maybe I could do this via: public class LatestExpertAssignmentRule : Rule
{
public override void Define()
{
AssignedToExpertFact assignment = null!;
L1TwilioTaskRouterEvent? reservationAccepted = null;
When()
.Match(() => reservationAccepted!, x => x.EventType == "reservation.accepted")
.Query(() => assignment, x => x
.Match<AssignedToExpertFact>()
.Collect()
.OrderBy(a => a.Timestamp)
.Where(a => a.Any())
.Select(a => a.Last())
);
Then()
.Yield(_ => new LatestAssignmentFact(assignment));
}
} But
I'm not really sure what to do here 🤔 Been running into a lot of gotchas along the way, maybe this is another one? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Closing as removing the |
Beta Was this translation helpful? Give feedback.
Closing as removing the
.Match(() => reservationAccepted!, x => x.EventType == "reservation.accepted")
which I seemed to just blindly glance over fixed the issue. As that was causing it to match many times when it didn't need to.