Eseper event timeout - timeout

I want to timeout events individually for each incoming event in esper. How to achieve that?
If i use time or batch windows, it will wait for other events to first fill the window ,only then the events are moved to rstream.

Use a named window with keep-all and put the condition when events get deleted into an on-delete.
create window CustomExpiryWindow.win:keepall() as MyEvent
insert into CustomExpiryWindow select * from MyEvent
on <.......> delete from CustomExpiryWindow where <......>
In Alternative there is an extension API for data windows where you could write code to keep and expire events.

Related

How do I delay clearing a ThingsBoard alarm?

I have a rule chain in ThingsBoard that does a Create Alarm when temperature is outside threshold and does a Clear Alarm otherwise. I receive a message using a Telegram bot when these events occur. That all works fine.
However when the temperature is hovering around the threshold, I can get many notifications as it goes in and out of the threshold temperature. That is somewhat annoying.
I would like to have the Clear Alarm activity only trigger if it is more than 5 minutes (say) since the last Create Alarm event was triggered.
Any tips on how to achieve this?
I finally worked out how to do this.
I added some server attributes to my device that define the temperatures that trigger alarms. I have a rule chain for controlling these alarms with the following nodes:
Enrichment - originator attributes to add the relevant attributes into the metadata associated with this message
Filter - script to detect if the temperature is outside the expected range
Filter - script to detect if the delay period has expired since the last time the alarm was triggered
Action - create alarm when script detects that temp is out of range
Action - clear alarm when script detects that delay period has expired
Transformation - script to update last alarm time attribute
Action - save attributes to persist updated alarm time attribute
Transformation - script to create a message about alarm set or cleared
Rule chain to handle sending the message to a Telegram bot
As an example, here is the script for checking if the delay period has expired before clearing the alarm:
var alarmTime = Number(metadata.ss_lastWaterTempAlarmTime);
var alarmDelay = Number(metadata.ss_clearAlarmTimeDelay);
return metadata.ts >= alarmDelay + alarmTime;
ss is the prefix added for server side attributes that have been added to metadata.
You can see the complete rule chain json in my Aquamon repo.

Esper EPL - Differentiate deleted events from released events in a timed window

I count events within a timed window. If more than 5 events arrive at that window, then I want to discard them all. Otherwise, the events are released after the waiting time.
My code goes something like this:
// Create a timed window of 10 seconds
create window MyWindow.win:time(10 sec) as MyEventType;
// Add to the timed window
insert into MyWindow select * from MyEventType;
//Delete from window if upper limit was reached
On MyEventType as newEvent
select and delete * from MyWindow as oldEvent
having COUNT(*) >= 5;
Additionally, a listener receives all events that leave the timed window:
select rstream * from MyWindow;
The problem with the example above is that both deleted and released events are forwarded to the listener (via rstream).
Question: how to differentiate deleted events from released ones?
There is nothing on the events afaik. I think an application could look at the time of the event and see if its older than current time. I can think of another option whereas a listener of on-delete receives the deleted events and not the expired ones which given the application a means to know what was deleted and what was expired.

Reminder using Signal R

I have a reminder functionality using signal R in asp.net mvc
I have userinterface to set the reminder time, If the current time matches the reminder time , it invokes a popup.
I successfully implemented this functionality with Signal R by checking the database once in every 30 seconds by using javascript timer. If current time does not match, it gives '0'.If it matches, it return '1' and the popup is shown across all browsers. But can this checking the db for every 30 seconds can be replaced by signal R ? is there any way to bring this whole thing to signal R?
You can use System.Threading.Timer to create a periodical method call to both client and server side. According to Sample project created for stocks
_timer = new Timer(UpdateStockPrices, null, _updateInterval, _updateInterval);
It creates and Event-Delegate and calls UpdateStockPrices event timely with period of __updateInterval.
In This event(code given below) you can broadcast the remainder message from server to all clients or clients who are associated with that remainder.
You can write code as :-
Clients.All.updateStockPrice(stock);
You can refer to Timer from link:-
http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx
Yes, you can use Timer in the appdomain scope, application scope or at the hub level. Just get the sample from nuget, called "Microsoft.AspNet.SignalR.Sample". It implements stock timer that periodically broadcasts changes to all clients.

Get past values from streams

Is it possible to get the last added value or previous values from a StreamController.broadcast / Stream.
Basically I have some subscriptions to streams like on('data') and on('ready') and I want for example that if someone listens to on('ready') after the event was triggered they can get the last value from the broadcast stream, eg. 'I\'m ready'.
Something like:
StreamController x = StreamController.broadcast();
first = x.first.then(doSomething);
x.add('oneOffEvent');
// first ~ 'oneOffEvent'
x.close()
other = x.last.then(doSomethingElse);
// other ~ 'oneOffEvent'
Is this even possible without caching the value somewhere else?
Broadcast Streams, by design, do not wait for subscriptions to fire events.
You can, however, do both a first and last subscription before adding events.
Add many subscriptions. That's the upside of broadcast subscriptions.

Cannot load to stream on onquit event of Word Application

I open a document with
WordApplication1.Connect;
WordApplication1.Documents.OpenOld(FileNameOLE,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam);
WordApplication1.Visible:=true;
and I want to save it to a Stream after it is closed but I get below error.
"Cannot open file used by another process."
What to do ? Thanks for help.
Sample
procedure TPatient.WordApplication1Quit(Sender: TObject);
var mem:TMemoryStream;
begin
WordApplication1.Disconnect;
WordApplication1.Quit;
//I get filename to global widestring variable File_OLE
mem:=Tmemorystream.Create;
mem.LoadFromFile(File_OLE); -------->>>>error here
mem.Position:=0;
It seems like Word is still blocking the access to the file. So you may have to wait a few milliseconds to seconds until the file is released. You can achieve this by Sleep and/or retrying to save a few times
In your sample procedure, Word is still running when you want to load the document in your TMemoryStream. Word is handling it's quit event at that time (go figure :P ) and hasn't shutdown yet.
What you could do is start a timer (TTimer with an interval of 500/1000) on the quit event and open your document in the timer event. Also don't call WordApplication1.Quit, because you are already quitting, just disconnect your WordApplication1.
An even better solution is to not rely on the quit event. Because when you start Word as in your first code section, and you open another Word document from Windows Explorer, the quit event won't come by when you close the document your application opened. Word will still remain active because it's hosting the other document too.
Add a TWordDocument to your form and when you open the document, connect the TWordDocument to the opened document. In the TWordDocument.Close event you can start a Timer and when the Timer fires, you can load your Document. An even better way is to not use timers but just save the document on the OnClose event to another file (.SaveAs) and load that file into the memorystream. This way you can be sure that the file is not opened by Word.

Resources