Are we using CreateTransientAsync correctly?

Struggling with an issue, and hoped someone on here could shed some light on it.
It might be we are using the software incorrectly.

Event Store Version: 3.1.0.0

EventStore.Client: 3.0.2

We have a Continuous Projection (called AllSales) and want to perform an adhoc query on in (get the total sum of sales performed today):

Here is the query:

fromAll()

.when({

$init: function (s, e) {

return {

total: 0, count: 0

}

},

‘Tahoe.Eposity.DomainEvents.SalesTransactionLineAddedEvent’: function (s, e) {

var today = new Date(‘2015-09-01’);

var eventDate = new Date(e.data.EntryDateTime);

if (today.getDate() == eventDate.getDate() &&

today.getMonth() == eventDate.getMonth() &&

today.getFullYear() == eventDate.getFullYear()) {

s.total += e.data.LineTotal;

s.count ++;

}

}

});

In our C# code, we have a prototype to show the issue:

while(true)

{

String queryname = Guid.NewGuid().ToString();

projectionsManager = new ProjectionsManager(new ConsoleLogger(), new IPEndPoint(address, 2113), TimeSpan.FromSeconds(10));

await projectionsManager.CreateTransientAsync(queryname, query, credentials);

var result = await projectionsManager.GetStateAsync(queryname, credentials);

Console.WriteLine(result);

Thread.Sleep(1000);

}

The first time round the loop, the result contains what looks like the expected value, however, all subsequent iterations just seem like strange values (a lot of repeating values):

{“total”:859.6099999999999,“count”:77}

{“total”:261.41,“count”:23}

{“total”:163.57999999999998,“count”:14}

{“total”:163.57999999999998,“count”:14}

{“total”:41.849999999999994,“count”:5}

{“total”:41.849999999999994,“count”:5}

{“total”:163.57999999999998,“count”:14}

{“total”:163.57999999999998,“count”:14}

{“total”:41.849999999999994,“count”:5}

{“total”:261.41,“count”:23}

Are doing something fundamentally wrong?

In addition, if we chang fromAll() to fromStream(‘AllSales’) we get no results, even though that is the correct stream name.

If we take the javascript query, and run it from the Admin GUI, we always get the expected values.

Any help in this matter would be appreciated.

Steven

Does anyone use CreateTransientAsync?

This is a show stopper for us, because the results returned from GetStateAsync changes each time we make calls in short succession.

The main issue is we are unsure if it’s a lack of understanding on our part, or if there is a problem with the .NET Driver.

Running the query manually from the Admin GUI produces the expected results (every time).

Steven

Ok, we got this issue sorted finally!

For anyone else interested, the problem was our assumption that CreateTransientAsync (even using await) does not actually return when the query is ready to run.

If you then call GetStatusAsync and keep checking the status (it will become completed shortly after) then call GetStateAsync.

Hope that makes sense.

Ah, yes the async applies to the HTTP operation not the underlying projection operation (there is no mechanism to implement this in ES at the moment). I guess there might be space for a higher level API encapsulating this implemented in the terms you mention here too.

Yeah, in our API for making these kind of calls, we just hide the fact keep checking the status so to the user, it looks like they make a call to fire a query and get the response all in one go.

I’ve opened https://github.com/EventStore/EventStore/issues/672 to track this.