cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Problems with async AddStreamEntry

drichter
15-Moonstone

Problems with async AddStreamEntry

Hi folks,

I have some issus with the AddStreamEntry service of a stream. I have a service which will add elements from a InfoTable to the stream (round about 500). I iterate through every element, log the iteration step and add stuff via AddStreamEntry to the Stream. In log I can see all 500 iterations. In Stream there are only ~30 elements.

I think that have something todo with the async call of AddStreamEntry. The AddStreamEntry maybe is slower than the iteration. After finish all iteration steps my service will end up without all AddStreamEntry calls. It there any solution for this problem?

ACCEPTED SOLUTION

Accepted Solutions

David,

Could you plz copy your code here?

Obviously async stream entries are quick, if the default stamp is same for entries then those corresponding rows will be skipped. So, try pause some milliseconds between each entries.

View solution in original post

4 REPLIES 4

David,

Could you plz copy your code here?

Obviously async stream entries are quick, if the default stamp is same for entries then those corresponding rows will be skipped. So, try pause some milliseconds between each entries.

drichter
15-Moonstone
(To:pselvaraj-1)

Copy my code is a little bit tricky because I use many ofter own service calls.

I try your recommendation and add a pause after each AddStreamEntry (first of 5ms but 1ms works too). This works but it seems no very elegant. If the database is to slow or other things are happen.

But this brings me an idear: I add a loop (with pause) at the end of the service. This loops will end if the entry count of stream and the entry count of the infotable are the same. Thx

You're welcome . You can try AddStremEntries which will do bulk insert.

Hi David,

Primary Key on Stream it's timestamp, you can't insert two entries at the same Timestamp, it will do an upsert when you try to insert two entries at the same Timestamp.

If timestamp it's not importat for you, just before the loop set:

var timestamp = new Date();

and on the end of the iteration:

timestamp = addMilliseconds(timestamp,1);

That way you will get a different timestamp for each entry.

But still if you have more process that calls your service and this process enters before 500 milliseconds you will have the same problem again

Announcements


Top Tags