I wrote a windows C# application that is running 24/7 and collecting sensoric data, storing it in a database.
Once every night, I run some algorithmns on the data from the previous day. The results are only useful if the app was active the whole previous day without major breaks (i.e. breaks more than 5 minutes will render results from that day useless).
Any ideas how to assure the app was running all the time on a day without major breaks?
- solution should work even if application/windows crashes and is restarted
- it is possible that there is no sensoric data in a long time, even if the app is running
First ideas
- Increase a database counter for the current day every minute. If the counter reaches the max 1440 minus a tolerance(60 min x 24 hours), the app was up all day. Seems complicated, needs a counter for each day. Will give headache on change from summer to winter time...
Persist the following two variables (in a database, a file, wherever you want):
- An integer. This will be your max number of seconds offline.
- A timestamp. This will be your last heartbeat. This needs to be UTC, to make it DST-proof.
Make your application do the following every couple seconds:
- Read the last timestamp.
- Compare it with the current (UTC) timestamp.
- If the difference is bigger than the integer, update the integer.
- Update the timestamp with the current UTC timestamp.
Every day, manually inspect the timestamp. Reset it to zero when you do so.