Hello,
Is there any method, we can trigger a subscription if the ThingWorx platform is going to shut down?
If not, is it possible to get the date and time when the last platform Shutdown happened?
I am looking for either the ThingStop Event just like ThingStart, or the server shutdown time.
Any pointers would be very Helpful.
Thanks and Regards,
Bhushan
Solved! Go to Solution.
Actually, I was looking for a trigger to and a subscription to execute when the system shutdown starts.
However, as that is not possible, I looked into the Application logs, as Pai suggested.
I was able to use the log ">>>>>>> PLATFORM SHUTDOWN START <<<<<<<<<" to identify when the system shutdown started.
I am getting this value on the trigger of ThingStart Event, on a system restart.
Below is the code I am using to fetch the last Platform shutdown.
// result: INFOTABLE dataShape: "LogEntry"
let QueryLog = Logs["ApplicationLog"].QueryLogEntries({
maxItems: 1 /* NUMBER {"defaultValue":500} */,
searchExpression: ">>>>>>> PLATFORM SHUTDOWN START <<<<<<<<<" /* STRING */,
fromLogLevel: undefined /* STRING */,
instance: undefined /* STRING */,
isRegex: undefined /* BOOLEAN {"defaultValue":false} */,
endDate: undefined /* DATETIME */,
origin: undefined /* STRING */,
thread: undefined /* STRING */,
platformId: undefined /* STRING */,
ascendingSearch: undefined /* BOOLEAN */,
oldestFirst: undefined /* BOOLEAN */,
toLogLevel: undefined /* STRING */,
user: undefined /* USERNAME */,
sortFieldName: undefined /* STRING */,
startDate: undefined /* DATETIME */
});
Thanks and Regards,
Bhushan
You should be able to gather this from information in the Application Log
In short, this is not implemented directly in the platform, as it is today.
There are 2 options I can think of:
1. As Pai suggested, when Platform starts, there's an INFO warning line in the ApplicationLog that says "WebApp started ...". That is the only 100% true single source of truth regarding when the platform started. You can read that line, but I don't know of a way to do that scalable - eg: there might be cases when you would not want to read the ApplicationLog too frequently.
2. In the PlatformSubsystem there's a service called GetPerformanceMetrics. That returns a line called "Amount of time the server has been running (milliseconds)". You can have a Timer running relativel frequently (since this service retrieves values in-memory), accessing this parameter, and creating a Property called "lastStartDate" based on some calculation (eg: detecting if the current value is smaller than last value, then this means the platform was restarted). The thing to be aware of this approach is that this parameter in bold above is reset also when the PlatformSubsystem is saved (eg: you changed some of its configuration), but assuming this does not happen in production (this should happen only initially in theory) it should work relatively reliably.
Actually, I was looking for a trigger to and a subscription to execute when the system shutdown starts.
However, as that is not possible, I looked into the Application logs, as Pai suggested.
I was able to use the log ">>>>>>> PLATFORM SHUTDOWN START <<<<<<<<<" to identify when the system shutdown started.
I am getting this value on the trigger of ThingStart Event, on a system restart.
Below is the code I am using to fetch the last Platform shutdown.
// result: INFOTABLE dataShape: "LogEntry"
let QueryLog = Logs["ApplicationLog"].QueryLogEntries({
maxItems: 1 /* NUMBER {"defaultValue":500} */,
searchExpression: ">>>>>>> PLATFORM SHUTDOWN START <<<<<<<<<" /* STRING */,
fromLogLevel: undefined /* STRING */,
instance: undefined /* STRING */,
isRegex: undefined /* BOOLEAN {"defaultValue":false} */,
endDate: undefined /* DATETIME */,
origin: undefined /* STRING */,
thread: undefined /* STRING */,
platformId: undefined /* STRING */,
ascendingSearch: undefined /* BOOLEAN */,
oldestFirst: undefined /* BOOLEAN */,
toLogLevel: undefined /* STRING */,
user: undefined /* USERNAME */,
sortFieldName: undefined /* STRING */,
startDate: undefined /* DATETIME */
});
Thanks and Regards,
Bhushan
Please note that it is better to look for platform start or use platform uptime vs. shutdown in case of 'Critical Shutdowns' that happen and do not put a clean shutdown message in the logs.