I had not since I was using the productRemovalSpans stream to output the data that was coming in. For instance, the StartDate and EndDate attributes in the sample I pasted has the dates as I expect them, except they shouldn’t have the .***Z part at the end because I’m stripping it off, and the Span attribute should have the difference in seconds (~61).
I did try debugging the projection, and weirdly enough, it acts as I expect it should. There are two cases (as I expect) where the it gets into the condition where it emits the ProductLikelyToBeReordered event to the productsLikelyToBeReordered stream.
So I stopped the projection, reset it, and then started it again. It still doesn’t create the two ProductLikelyToBeReordered events in the productsLikelyToBeReordered stream. It does update the productRemovalSpans stream.
When it runs normally outside of the debugger, the string.split function and Date constructor don’t work as expected.
I’ve included some of the logging:
[15816,11,16:15:38.560] Updating ‘Products Likely To Be Reordered’ projection source to 'function convert_date(thedate){
var pieces = thedate.toString().split(".");
return pieces[0];
}
fromCategory(‘orderid’).foreachStream().when({
‘$init’: function(){
return { productStartDates: {}};
},
‘OrderEntry.Events.ProductAddedToOrder’ : function (state, event) {
state.productStartDates[event.data.ProductId] = event.data.Occurred;
return state;
},
‘OrderEntry.Events.ProductRemovedFromOrder’ : function (state, event) {
var productStartDate = convert_date(state.productStartDates[event.data.ProductId]);
var productEndDate = convert_date(event.data.Occurred);
var startDate = new Date(productStartDate);
var endDate = new Date(productEndDate);
var difference = (endDate.getTime() - startDate.getTime()) / 1000;
emit(‘productRemovalSpans’, ‘ProductsLikelyToBeReordered’, {
CustomerId: event.data.CustomerId,
ProductId: event.data.ProductId,
StartDate: productStartDate,
EndDate: productEndDate,
Span: difference
});
if(difference > 10) {
emit(‘productsLikelyToBeReordered’, “ProductLikelyToBeReordered”, {
CustomerId: event.data.CustomerId,
ProductId: event.data.ProductId
});
}
return state;
}
});’ (Requested type is: ‘’)
[15816,11,16:15:38.560] ‘Products Likely To Be Reordered’ projection source has been written
[15816,11,16:15:41.663] Enabling ‘Products Likely To Be Reordered’ projection
[15816,11,16:15:41.796] ‘Products Likely To Be Reordered’ projection source has been written
[15816,11,16:32:55.921] Disabling ‘Products Likely To Be Reordered’ projection
[15816,14,16:32:55.929] Writing checkpoint for Products Likely To Be Reordered at $ce-orderid: 16 with expected version number 3
[15816,14,16:32:55.929] Checkpoint has been written for projection Products Likely To Be Reordered at sequence number 4 (current)
[15816,11,16:32:55.961] ‘Products Likely To Be Reordered’ projection source has been written
[15816,11,16:33:01.957] Resetting ‘Products Likely To Be Reordered’ projection
[15816,11,16:33:01.988] ‘Products Likely To Be Reordered’ projection source has been written
[15816,11,16:33:04.928] Disabling ‘Products Likely To Be Reordered’ projection
[15816,11,16:33:04.928] ‘Products Likely To Be Reordered’ projection source has been written
[15816,11,16:40:56.373] Enabling ‘Products Likely To Be Reordered’ projection
[15816,11,16:40:56.393] ‘Products Likely To Be Reordered’ projection source has been written
[15816,11,16:42:09.673] Resetting ‘Products Likely To Be Reordered’ projection
[15816,14,16:42:09.689] Writing checkpoint for Products Likely To Be Reordered at $ce-orderid: 16 with expected version number 4
[15816,14,16:42:09.689] Checkpoint has been written for projection Products Likely To Be Reordered at sequence number 5 (current)
[15816,11,16:42:09.735] ‘Products Likely To Be Reordered’ projection source has been written
[15816,11,16:42:13.968] Disabling ‘Products Likely To Be Reordered’ projection
[15816,14,16:42:14.093] Writing checkpoint for Products Likely To Be Reordered at $ce-orderid: 16 with expected version number 5
[15816,14,16:42:14.093] Checkpoint has been written for projection Products Likely To Be Reordered at sequence number 6 (current)
[15816,11,16:42:14.109] ‘Products Likely To Be Reordered’ projection source has been written
[15816,11,16:42:29.625] Resetting ‘Products Likely To Be Reordered’ projection
[15816,11,16:42:29.639] ‘Products Likely To Be Reordered’ projection source has been written
[15816,11,16:42:37.731] Disabling ‘Products Likely To Be Reordered’ projection
[15816,11,16:42:37.735] ‘Products Likely To Be Reordered’ projection source has been written
[15816,11,16:48:31.972] Disabling ‘Products Likely To Be Reordered’ projection
[15816,11,16:48:31.972] ‘Products Likely To Be Reordered’ projection source has been written
[15816,11,16:49:09.458] Resetting ‘Products Likely To Be Reordered’ projection
[15816,11,16:49:09.474] ‘Products Likely To Be Reordered’ projection source has been written
[15816,11,16:49:13.964] Enabling ‘Products Likely To Be Reordered’ projection
[15816,11,16:49:13.984] ‘Products Likely To Be Reordered’ projection source has been written