Skip to content

refacto: make async persisting logic more readable and maintainable#155

Open
GhilesA wants to merge 1 commit intomainfrom
refacto/improve_persisted_poller_code
Open

refacto: make async persisting logic more readable and maintainable#155
GhilesA wants to merge 1 commit intomainfrom
refacto/improve_persisted_poller_code

Conversation

@GhilesA
Copy link

@GhilesA GhilesA commented Jan 27, 2026

PR Summary

use a ScheduledExecutorService to handle the background periodic logic safely cancel, wait for completion and close the threads and executor using its api
remove Thread::sleep from the code

@jonenst some questions are still remaining, can you provide some background info on the TODOs and FIXME ?

@GhilesA GhilesA requested a review from jonenst January 27, 2026 08:24
@GhilesA GhilesA force-pushed the refacto/improve_persisted_poller_code branch 5 times, most recently from d1ebce7 to 21a74d9 Compare February 2, 2026 14:47
@GhilesA GhilesA force-pushed the refacto/improve_persisted_poller_code branch from 21a74d9 to f339863 Compare February 3, 2026 08:42
@GhilesA GhilesA force-pushed the refacto/improve_persisted_poller_code branch 4 times, most recently from 93b2b4f to 48a00c7 Compare February 6, 2026 17:04
@GhilesA GhilesA marked this pull request as ready for review February 6, 2026 17:04
@GhilesA GhilesA force-pushed the refacto/improve_persisted_poller_code branch 6 times, most recently from 871f120 to 2a4ac7a Compare February 16, 2026 17:03
@jonenst jonenst requested a review from Copilot February 17, 2026 08:42
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the asynchronous result persistence logic to improve readability and maintainability by replacing manual thread management with ScheduledExecutorService. The refactoring eliminates Thread.sleep() calls and introduces better structured components for batch processing and polling.

Changes:

  • Replaced SensitivityResultWriterPersisted with SensitivityResultPersistedWriter, refactoring from manual thread management to ScheduledExecutorService-based scheduling
  • Introduced new components: BatchAsyncPoller for generic batch polling logic, ExecutorsProviderService for thread pool creation, and BatchAsyncPollerFactory for poller instantiation
  • Updated SensitivityAnalysisWorkerService to use the new writer with simplified async completion handling

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
src/main/java/org/gridsuite/sensitivityanalysis/server/util/SensitivityResultPersistedWriter.java New implementation replacing the old writer, using ScheduledExecutorService and delegating to BatchAsyncPoller instances
src/main/java/org/gridsuite/sensitivityanalysis/server/util/BatchAsyncPoller.java Core component for batch polling and periodic data draining with proper cancellation and completion handling
src/main/java/org/gridsuite/sensitivityanalysis/server/util/ExecutorsProviderService.java Spring service providing configured ScheduledExecutorService instances with custom thread naming
src/main/java/org/gridsuite/sensitivityanalysis/server/util/BatchAsyncPollerFactory.java Factory for creating BatchAsyncPoller instances (should be marked as Spring service)
src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisWorkerService.java Integrates the new writer with updated async completion and error handling logic
src/test/java/org/gridsuite/sensitivityanalysis/server/util/SensitivityResultPersistedWriterTest.java Unit tests for the new writer implementation
src/test/java/org/gridsuite/sensitivityanalysis/server/util/BatchAsyncPollerTest.java Comprehensive unit tests for the batch poller
src/test/java/org/gridsuite/sensitivityanalysis/server/util/ExecutorsProviderServiceTest.java Unit tests for the executor service provider
src/main/java/org/gridsuite/sensitivityanalysis/server/util/SensitivityResultWriterPersisted.java Deleted - replaced by SensitivityResultPersistedWriter
src/test/java/org/gridsuite/sensitivityanalysis/server/util/SensitivityResultWriterPersistedTest.java Deleted - replaced by SensitivityResultPersistedWriterTest

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@GhilesA GhilesA force-pushed the refacto/improve_persisted_poller_code branch 4 times, most recently from 675e804 to eb786f5 Compare February 18, 2026 08:43
@GhilesA GhilesA force-pushed the refacto/improve_persisted_poller_code branch 4 times, most recently from 55cb463 to 6dd76d5 Compare February 20, 2026 09:02
use a ScheduledExecutorService to handle the background periodic logic
safely cancel, wait for completion and close the threads and executor
using its api
remove Thread::sleep from the code
@GhilesA GhilesA force-pushed the refacto/improve_persisted_poller_code branch from 6dd76d5 to b1ad449 Compare February 20, 2026 13:56
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants