Ankit Gupta, to put it simply, if I run a for-loop on a "thing" to acknowledge several alerts, only one or two will be written to "AlarmsHistory" stream. The reason being is that the for-loop will complete its cycle in less than 1 ms, meaning that all alerts processed by the for-loop will share the same timestamp. In turn, this will overwrite records in the "AlertHistory" stream. Can you suggest a way a safe way of introducing 1 ms delay? There is also a chance that another alert maybe acknowledged on another "thing" during same millisecond. Thanks.
You may ask why would you like to do that?! In our application machine alarms are mapped to alerts. No intervention from the users' point of view is required, just visibility. So, if a number of Boolean properties become 'true', corresponding alerts are raised. On 'false' condition, alerts are automatically acknowledged. The reason behind such approach was to utilise various ThingWorx alert services.
Having exhausted all my options available, I've decided to use the pause() function as suggested by Carles Coll in Re: Asyncronous Streams and Delayed Calculations Execution?
pause(1); //wait 1 ms
This way entries in "AlertHistory" stream are populated correctly with a different timestamp. Not sure though how it will affect the performance. There not as many machines as described in the above post and alerts should be a rare occasion.