Update InitializeEdgesWorker.java to refresh Edges every 30 minutes
Right now if a new Edge Device is added to the Backend we always need to restart the Backend. This fix handles this as it calls the InitializeEdgesWorker every 30 Minutes without setting the Edges Offline again after first run.
@sfeilmeier i guess it looks better now :)
Summary of Changes in InitializeEdgesWorker
We've made several key updates to the InitializeEdgesWorker class aimed at enhancing its functionality, efficiency, and reliability. Below is an overview of these changes and the motivations behind them:
Key Updates
-
Scheduled Task Execution:
- Previously: The class executed a one-time cache update at startup.
- Now: We've introduced a
ScheduledExecutorServiceto periodically update the cache every 30 minutes. This ensures the cache remains up-to-date without manual intervention.
-
Enhanced Error Handling:
- Improvement: Enhanced logging for error scenarios, particularly when connecting to Postgres, to aid in troubleshooting.
-
Optimization:
- Change: Added a flag (
isMarkAllEdgesAsOfflineCalled) to ensure that the operation to mark all edges as offline is executed only once. This prevents unnecessary database updates.
- Change: Added a flag (
-
Code Organization:
- Refactoring: Centralized the caching logic within
runCachingEdgesTask, simplifying thestart()method and reducing code duplication.
- Refactoring: Centralized the caching logic within
Rationale and Specific Issue Addressed
The introduction of periodic caching is not only aimed at keeping the data fresh but also at addressing a specific issue observed in the system. When a new edge device is added to the backend, the UI currently experiences a hang-up, failing to display the new device immediately. This situation results in a less responsive and potentially confusing user experience.
With the newly implemented periodic cache update, we ensure that any new edge devices are integrated into the cache within a maximum of 30 minutes, thereby "fixing" the issue of the UI hang-up by ensuring that new devices are eventually displayed without requiring manual intervention or a system restart.
This approach significantly improves the system's robustness, ensuring that changes in the backend are accurately and timely reflected in the UI, enhancing the overall user experience.
Conclusion
These updates are intended to make the InitializeEdgesWorker more robust, efficient, and easier to maintain. More importantly, they address a specific operational issue that affects user interaction with the system. We believe these changes align with our goals for improving data accuracy, system performance, and user experience. We welcome any feedback or suggestions for further improvements.
Do you maybe think it is better to somehow "subscribe" to the Database and check for changes and only then Update the EdgeCache?
@michaelgrill: Can you please add your opinion?
This PR has been automatically marked as stale due to inactivity. It will be closed in 7 days if no further activity occurs.
This PR has been closed due to inactivity
It was automatically closed because there has been no recent activity. If the PR is still relevant, please feel free to reopen and update it and add any new information.