smartinspectpython.siconfigurationtimer
Module: siconfigurationtimer.py
Revision History
Date | Version | Description |
---|---|---|
2023/05/30 | 3.0.0.0 | Initial Version. |
2023/06/09 | 3.0.8.0 | Added call to RaiseInfoEvent for when a configuration settings file is changed and reloaded. |
Monitors a SmartInspect configuration settings file for changes and reloads the configuration when it does.
Use this class to monitor and automatically reload SmartInspect configuration files. This class periodically checks if the related configuration file has changed (by comparing the last modified datetime) and automatically tries to reload the configuration properties. You can pass the SmartInspect object to configure, the path of the configuration file to monitor, and the interval in which the path should check for changes.
For information about SmartInspect configuration files, please refer to the documentation of the SmartInspect.LoadConfiguration method.
Threadsafety:
This class is fully thread-safe.
View Sample Code
from smartinspectpython.siauto import *
# load SmartInspect settings from a configuration settings file.
siConfigPath:str = "./smartinspect.config"
SIAuto.Si.LoadConfiguration(siConfigPath)
# start monitoring the configuration file for changes, and reload it when it changes.
# this will check the file for changes every 60 seconds.
siConfigTask:SIConfigurationTimer = SIConfigurationTimer(SIAuto.Si, siConfigPath, 60)
...
# get smartinspect logger reference.
logsi:SISession = SIAuto.Main
...
The following is the configuration settings file contents:
; smartinspect.config
; SmartInspect Logging Configuration General settings.
; - "Enabled" parameter to turn logging on (True) or off (False).
; - "Level" parameter to control the logging level (Debug|Verbose|Message|Warning|Error).
; - "AppName" parameter to control the application name.
Enabled = False
Level = Verbose
DefaultLevel = Debug
AppName = My Application Name
; SmartInspect Logging Configuration Output settings.
; - Log to SmartInspect Console Viewer running on the specified network address.
Connections = tcp(host=localhost, port=4228, timeout=5000, reconnect=true, reconnect.interval=10s, async.enabled=true)
; - Log to a file:
;Connections = "file(filename=\"./tests/logfiles/logfile.log\", rotate=hourly, maxparts=24, append=true)"
; - Log to an encrypted file:
;Connections = "file(filename=\"./tests/logfiles/logfileEncrypted.sil\", encrypt=true, key=""1234567890123456"", rotate=hourly, maxparts=14, append=true)"
; set defaults for new sessions
; note that session defaults do not apply to the SIAuto.Main session, since
; this session was already added before a configuration file can be loaded.
; session defaults only apply to newly added sessions and do not affect existing sessions.
SessionDefaults.Active = True
SessionDefaults.Level = Message
SessionDefaults.ColorBG = 0xFFFFFF
; configure some individual session properties.
; note that this does not add the session to the sessionmanager; it simply
; sets the property values IF the session name already exists.
Session.Main.Active = True
Session.Main.ColorBG = 0xFFFFFF
Initializes a new instance of the class.
Arguments:
- smartInspect (SmartInspect): The SmartInspect object to configure.
- fileName (str): The path of the configuration file to monitor.
- interval (int): The interval (in seconds) in which this timer should check for changes to the configuration file. Default value is 60 (seconds).
Raises:
- SIArgumentNullException: The smartInspect or fileName parameter is null.
- ArgumentError: The interval parameter is less than 1 or greater than 300 (seconds).
The monitoring of the file begins immediately.
Starts monitoring the configuration file for changes.
This method is called automatically when a new instance of the class is created. It can also be called after issuing a "Stop" method call, to restart monitoring of the configuration file.
It will start a new thread named "SiConfigFileMonitorTask" that will monitor a specified configuration file for changes at a selected interval, and reload the configuration automatically.