openems icon indicating copy to clipboard operation
openems copied to clipboard

Update InitializeEdgesWorker.java to refresh Edges every 30 minutes

Open Sn0w3y opened this issue 1 year ago • 7 comments

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.

Sn0w3y avatar Feb 15 '24 19:02 Sn0w3y

Code Coverage

github-actions[bot] avatar Mar 05 '24 05:03 github-actions[bot]

@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

  1. Scheduled Task Execution:

    • Previously: The class executed a one-time cache update at startup.
    • Now: We've introduced a ScheduledExecutorService to periodically update the cache every 30 minutes. This ensures the cache remains up-to-date without manual intervention.
  2. Enhanced Error Handling:

    • Improvement: Enhanced logging for error scenarios, particularly when connecting to Postgres, to aid in troubleshooting.
  3. 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.
  4. Code Organization:

    • Refactoring: Centralized the caching logic within runCachingEdgesTask, simplifying the start() method and reducing code duplication.

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?

Sn0w3y avatar Mar 05 '24 05:03 Sn0w3y

Code Coverage

github-actions[bot] avatar Mar 05 '24 05:03 github-actions[bot]

@michaelgrill: Can you please add your opinion?

sfeilmeier avatar Mar 11 '24 08:03 sfeilmeier

Code Coverage

github-actions[bot] avatar Apr 01 '24 04:04 github-actions[bot]

Code Coverage

github-actions[bot] avatar Apr 02 '24 16:04 github-actions[bot]

Code Coverage

github-actions[bot] avatar Apr 16 '24 20:04 github-actions[bot]

This PR has been automatically marked as stale due to inactivity. It will be closed in 7 days if no further activity occurs.

github-actions[bot] avatar Sep 19 '25 13:09 github-actions[bot]

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.

github-actions[bot] avatar Oct 12 '25 02:10 github-actions[bot]