Handling Long-Running Report Execution in Bold Reports
This article explains how to identify long-running report executions, automatically stop report rendering when a timeout threshold is exceeded, and notify users when report execution is cancelled.
Although Bold Reports does not provide a built-in feature to automatically detect and terminate long-running reports, you can achieve this by using Report Viewer events with custom timeout handling.
The implementation consists of the following steps:
- Monitor report execution duration.
- Detect reports that exceed a predefined timeout threshold.
- Cancel report rendering automatically.
- Notify users when report rendering is cancelled.
Monitor Long-Running Report Execution
This approach uses Report Viewer events to measure the time required to render a report.
The following events are used:
renderingBeginrenderingComplete
How It Works
- Capture the timestamp when report rendering begins.
- Capture the timestamp when report rendering completes.
- Calculate the total report execution time.
- Compare the execution time with a predefined threshold.
Sample Code
let startTime;
renderingBegin: function () {
startTime = Date.now();
},
renderingComplete: function () {
const duration = (Date.now() - startTime) / 1000;
if (duration > 10) {
console.log("Long running report detected");
}
}
Benefits
- Identifies reports with excessive execution time.
- Measures report execution duration.
- Helps monitor report performance.
- Detects reports that exceed the configured threshold.
Automatically Stop Long-Running Reports
When a report exceeds the configured execution limit, report rendering can be cancelled automatically.
This helps prevent reports from consuming server resources indefinitely and provides immediate feedback to users.
How It Works
- Start a timeout timer before report processing begins.
- Wait until the configured timeout threshold is reached.
- Cancel report rendering if the report is still processing.
- Notify the user that report rendering has been cancelled.
Sample Code
let timeoutId;
ajaxBeforeLoad: function () {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
const viewer = $("#viewer").data("boldReportViewer");
if (viewer && viewer.cancelRendering) {
viewer.cancelRendering();
}
alert("Report execution exceeded timeout limit.");
}, 10000);
}
Benefits
- Automatically stops long-running reports.
- Prevents excessive resource consumption.
- Improves application responsiveness.
- Reduces the impact of inefficient reports.
Note: In this example, the timeout is set to 10 seconds (10,000 milliseconds). Adjust the timeout value based on your application requirements.
Notify Users When Report Rendering Is Cancelled
When report rendering is cancelled because the configured timeout limit is exceeded, users should be informed about the reason.
You can display a custom message in the Report Viewer.
Sample Code
renderingBegin: function(args) {
setTimeout(() => {
var reportviewerObj = $('#viewer').data('boldReportViewer');
reportviewerObj._renderErrorMsg(
"Report execution exceeded the allowed time limit. Please review the selected parameters or contact Support."
);
}, 10000);
}
Benefits
- Clearly informs users why report rendering did not complete.
- Reduces repeated report execution attempts.
- Improves the user experience.
- Minimizes unnecessary support requests.
Configuration Requirements
When implementing this solution, ensure that the following configuration values are set correctly:
reportServiceUrlreportServerUrlserviceAuthorizationToken
Also review the timeout settings configured at the following levels:
- Database
- Application
- Hosting environment
Ensure that these timeout settings align with the maximum acceptable report execution duration for your environment.
Recommended Approach
To effectively handle long-running reports:
- Monitor report execution using Report Viewer events.
- Define an appropriate execution timeout threshold.
- Automatically cancel report rendering when the threshold is exceeded.
- Notify users when report rendering is cancelled.
- Review and optimize reports that frequently exceed the configured timeout.
Sample Application
A sample application that demonstrates how to detect long-running report executions, automatically cancel report rendering after a configured timeout, and notify users is attached to this article.
Download the attached LongRunningReportCancellationSample.zip sample application.
Note: Before running the sample application, update the following configuration values to match your environment.
Required Configuration
reportServiceUrl:
"https://adhoc.boldreports.com/reporting/reportservice/api/Viewer",
reportServerUrl:
"https://adhoc.boldreports.com/reporting/api/site/reportsdemo",
serviceAuthorizationToken:
"bearer <your-service-authorization-token>",
reportPath:
"/Reports_POC/Product Measurement and Attributes Report"
Configuration Details
- reportServiceUrl – Specifies the Report Service API endpoint used by the Report Viewer.
- reportServerUrl – Specifies the Report Server URL where the report is hosted.
- serviceAuthorizationToken – Specifies the authorization token required to access Report Server resources.
- reportPath – Specifies the path of the report to render and monitor.
Important: Replace the sample URLs, authorization token, and report path with the values for your environment before running the application.
Conclusion
By using Report Viewer events together with custom timeout handling, you can detect long-running report executions, automatically cancel report rendering when a timeout threshold is exceeded, and notify users about the cancellation. This approach helps prevent excessive resource consumption while providing a better user experience through clear and timely feedback.