-
Notifications
You must be signed in to change notification settings - Fork 100
Report log issue in pharmacy reports #11701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe changes refactor the report logging mechanism to operate asynchronously. The synchronous usage of ReportLogFacade in ReportTimerController has been replaced with an asynchronous ReportLogAsyncService. ReportTimerController now creates and awaits a Future from the asynchronous service. Additionally, the ReportsTransfer class now wraps report generation logic with execution time tracking via ReportTimerController. New report types have been added to the DisbursementReports enum, and the ReportLog entity has been updated to accommodate a nullable endTime with corresponding execution time calculations. Changes
Sequence Diagram(s)sequenceDiagram
participant Controller as ReportTimerController
participant AsyncService as ReportLogAsyncService
participant LogFacade as ReportLogFacade
participant ReportGen as Report Generation Logic
Controller->>Controller: Create ReportLog (capture startTime)
Controller->>AsyncService: logReport(reportLog) (asynchronous call)
AsyncService->>LogFacade: Create/Edit ReportLog
AsyncService-->>Controller: Return CompletableFuture<ReportLog>
Controller->>Controller: Await result (futureLog.get())
ReportGen->>Controller: Execute report generation logic
Controller->>Controller: Capture endTime
Controller->>Controller: Set endTime via ReportLog.setEndTime()
Controller->>AsyncService: logReport(updated ReportLog) (asynchronous update)
Possibly related PRs
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (4)
src/main/java/com/divudi/service/ReportLogAsyncService.java (2)
29-37
: Consider adding transaction retry mechanism.While the error handling is good, there's no retry mechanism for transient database errors. For async operations, it might be beneficial to add retry logic for temporary failures.
if (reportLog.getId() == null) { try { getFacade().create(reportLog); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Error occurred while saving the report log", e); + // Consider implementing retry logic for transient errors + // e.g., using exponential backoff strategy } } else { try { getFacade().edit(reportLog); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Error occurred while updating the report log", e); } }
42-44
: Consider returning the field directly.The getter method is simple enough that it doesn't need a dedicated method. You could access the field directly, especially since the class is already a service.
src/main/java/com/divudi/bean/common/ReportTimerController.java (2)
32-34
: Consider avoiding.get()
if full asynchronicity is desired.Calling
futureLog.get()
blocks the thread, making the operation effectively synchronous. If the goal is to offload logging entirely, consider removing or deferring the.get()
call.
42-44
: Capture the second log update result or handle errors.You are “fire-and-forget” calling
reportLogAsyncService.logReport(savedLog)
. Consider capturing the returnedFuture<ReportLog>
or checking for errors to ensure that any logging failures are detected.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
src/main/java/com/divudi/bean/common/ReportTimerController.java
(2 hunks)src/main/java/com/divudi/bean/pharmacy/ReportsTransfer.java
(6 hunks)src/main/java/com/divudi/core/data/reports/DisbursementReports.java
(1 hunks)src/main/java/com/divudi/core/entity/report/ReportLog.java
(3 hunks)src/main/java/com/divudi/service/ReportLogAsyncService.java
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/main/java/com/divudi/service/ReportLogAsyncService.java (1)
src/main/java/com/divudi/bean/common/ReportTimerController.java (1)
Stateless
(17-47)
src/main/java/com/divudi/bean/common/ReportTimerController.java (1)
src/main/java/com/divudi/service/ReportLogAsyncService.java (1)
Stateless
(14-45)
🔇 Additional comments (11)
src/main/java/com/divudi/core/data/reports/DisbursementReports.java (1)
4-5
: New enum constants added for tracking report execution.These new enum constants will be used to identify and track the execution of transfer issue and receive reports in the asynchronous logging system.
src/main/java/com/divudi/core/entity/report/ReportLog.java (3)
38-38
: Column constraint changed to allow null end times.Making the
endTime
column nullable is essential for the asynchronous logging system. It allows creating a log entry at the start of report execution with a nullendTime
, which will be updated after the report completes.
55-55
: Null-safety check added for execution time calculation.This change ensures that execution time is only calculated when both start and end times are available, preventing potential NullPointerExceptions.
116-122
: Added setter for endTime with execution time recalculation.This method is crucial for the asynchronous logging implementation. It allows updating the end time of a report execution and automatically recalculates the execution time if both start and end times are available.
src/main/java/com/divudi/bean/pharmacy/ReportsTransfer.java (2)
454-507
: Wrapped report execution with asynchronous tracking.The report generation logic has been refactored to use the asynchronous tracking system. This ensures that report execution times are logged without blocking the main operation, improving system responsiveness.
1705-1735
: Implemented asynchronous tracking for transfer receive report.Similar to the issue report, the receive report now uses asynchronous execution time tracking. This change is consistent with the overall approach of tracking report performance without impacting user experience.
src/main/java/com/divudi/service/ReportLogAsyncService.java (2)
1-20
: New asynchronous service for report logging.This service implements the asynchronous logging mechanism needed for tracking report execution times. The class is properly annotated with
@Stateless
and includes appropriate dependencies.
21-40
: Implemented asynchronous report logging method.The
@Asynchronous
annotation ensures this method runs in a separate thread, preventing it from blocking the main execution flow. The method handles both creation and updating of report logs, with proper null checks and error handling.src/main/java/com/divudi/bean/common/ReportTimerController.java (3)
6-7
: Imports aligned with new asynchronous approach.These additions for
ReportLogAsyncService
andFuture
correctly support the async logging mechanism.Also applies to: 12-12
22-22
: Dependency injection forReportLogAsyncService
looks good.Replacing the old synchronous dependency with this async EJB is consistent with your asynchronous logging pattern.
27-29
: Initialization ofReportLog
at start time is correct.Creating a new
ReportLog
with anull
endTime offers flexibility for finalizing the log once the execution completes.
Summary by CodeRabbit
New Features
Refactor