@@ -38154,7 +38154,7 @@ const constants = __nccwpck_require__(9350);
3815438154const ActionInput = __nccwpck_require__(460);
3815538155const ReportService = __nccwpck_require__(9427);
3815638156const ReportProcessor = __nccwpck_require__(4140);
38157- const TimeoutManager = __nccwpck_require__(933 );
38157+ const TimeManager = __nccwpck_require__(9991 );
3815838158
3815938159async function run() {
3816038160 try {
@@ -38172,7 +38172,7 @@ async function run() {
3817238172 core.info('Running in test mode with mock API responses');
3817338173 }
3817438174
38175- const timeoutManager = new TimeoutManager (userTimeout
38175+ const timeManager = new TimeManager (userTimeout
3817638176 || constants.DEFAULT_USER_TIMEOUT_SECONDS);
3817738177 const reportService = new ReportService(authHeader, isTestMode);
3817838178
@@ -38185,7 +38185,7 @@ async function run() {
3818538185 userTimeout,
3818638186 };
3818738187
38188- timeoutManager.check ();
38188+ timeManager.checkTimeout ();
3818938189 let reportData = await reportService.fetchReport(initialParams);
3819038190 let { retryCount: maxRetries, pollingInterval } = reportData;
3819138191
@@ -38200,7 +38200,7 @@ async function run() {
3820038200 if (reportData.reportStatus === constants.REPORT_STATUS.IN_PROGRESS) {
3820138201 reportData = await reportService.pollReport(
3820238202 initialParams,
38203- timeoutManager ,
38203+ timeManager ,
3820438204 maxRetries,
3820538205 pollingInterval,
3820638206 );
@@ -38683,7 +38683,8 @@ class ReportProcessor {
3868338683 summary.write();
3868438684 if (reportData?.report?.richHtml) {
3868538685 const report = `<!DOCTYPE html> <html><head><style>${reportData?.report?.richCss}</style></head> ${reportData?.report?.richHtml}</html>`;
38686- await UploadFileForArtifact.saveReportInFile(report);
38686+ const artifactObj = new UploadFileForArtifact(report);
38687+ await artifactObj.saveReportInFile();
3868738688 }
3868838689 } catch (error) {
3868938690 core.info(`Error processing report: ${JSON.stringify(error)}`);
@@ -38743,9 +38744,11 @@ class ReportService {
3874338744 };
3874438745 }
3874538746
38746- async pollReport(params, timeoutManager , maxRetries, pollingInterval) {
38747+ async pollReport(params, timeManager , maxRetries, pollingInterval) {
3874738748 const poll = async (retries) => {
38748- timeoutManager.check();
38749+ if (timeManager.checkTimeout()) {
38750+ return this.handleErrorStatus(constants.REPORT_STATUS.IN_PROGRESS);
38751+ }
3874938752
3875038753 const reportData = await this.fetchReport({
3875138754 ...params,
@@ -38761,7 +38764,7 @@ class ReportService {
3876138764 }
3876238765
3876338766 if (status === constants.REPORT_STATUS.IN_PROGRESS && retries < maxRetries) {
38764- await new Promise((resolve) => setTimeout(resolve, pollingInterval * 1000) );
38767+ await timeManager.sleep( pollingInterval);
3876538768 return poll(retries + 1);
3876638769 }
3876738770
@@ -38772,15 +38775,16 @@ class ReportService {
3877238775 return poll(0);
3877338776 }
3877438777
38775- static handleErrorStatus(status, reportData) {
38778+ static handleErrorStatus(status, reportData = {} ) {
3877638779 const errorMessages = {
38777- ERROR: 'Error occurred while fetching report',
38780+ ERROR: 'Unable to Fetch Report',
38781+ IN_PROGRESS: 'Report is still in progress',
3877838782 };
3877938783
3878038784 return {
3878138785 errorMessage: errorMessages[status] || `Unexpected status: ${status}`,
3878238786 reportStatus: status,
38783- report: reportData.report,
38787+ report: status === constants.REPORT_STATUS.IN_PROGRESS ? { basicHtml: '<pre>Report generation not completed, please try again after increasing report timeout</pre>' } : reportData.report,
3878438788 };
3878538789 }
3878638790}
@@ -38790,23 +38794,32 @@ module.exports = ReportService;
3879038794
3879138795/***/ }),
3879238796
38793- /***/ 933 :
38797+ /***/ 9991 :
3879438798/***/ ((module) => {
3879538799
38796- class TimeoutManager {
38800+ class TimeManager {
3879738801 constructor(timeoutSeconds) {
3879838802 this.timeoutMs = timeoutSeconds * 1000;
3879938803 this.startTime = Date.now();
3880038804 }
3880138805
38802- check () {
38806+ checkTimeout () {
3880338807 if (Date.now() - this.startTime >= this.timeoutMs) {
3880438808 throw new Error(`Operation timed out after ${this.timeoutMs / 1000} seconds`);
3880538809 }
3880638810 }
38811+
38812+ /**
38813+ * Sleep for specified seconds
38814+ * @param {number} seconds - Number of seconds to sleep
38815+ * @returns {Promise} - Promise that resolves after the specified time
38816+ */
38817+ static async sleep(seconds) {
38818+ return new Promise((resolve) => setTimeout(resolve, seconds * 1000));
38819+ }
3880738820}
3880838821
38809- module.exports = TimeoutManager ;
38822+ module.exports = TimeManager ;
3881038823
3881138824
3881238825/***/ }),
@@ -38819,6 +38832,10 @@ const path = __nccwpck_require__(6928);
3881938832const core = __nccwpck_require__(7484);
3882038833
3882138834class UploadFileForArtifact {
38835+ constructor(report) {
38836+ this.report = report;
38837+ }
38838+
3882238839 static async saveReportInFile(report) {
3882338840 if (!report) {
3882438841 core.debug('No HTML content available to save as artifact');
0 commit comments