From 331d3b9e9c22fca32c582235d78a8840740fdf4b Mon Sep 17 00:00:00 2001 From: Nishan Date: Tue, 8 Apr 2025 13:35:18 +0530 Subject: [PATCH] fix cleanup script --- app/public/js/index.js | 9 ++++++++- facilitator/src/services/examService.js | 3 +++ facilitator/src/utils/redisClient.js | 8 ++++---- scripts/install.ps1 | 2 +- scripts/install.sh | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/public/js/index.js b/app/public/js/index.js index 066934b..4a37a5e 100644 --- a/app/public/js/index.js +++ b/app/public/js/index.js @@ -381,6 +381,13 @@ document.addEventListener('DOMContentLoaded', function() { showLoadingOverlay(); // Show the loading overlay instead of pageLoader updateLoadingMessage('Starting lab environment...'); updateExamInfo(`Lab: ${selectedLab.name} | Difficulty: ${selectedLab.difficulty || 'Medium'}`); + let userAgent = ''; + try { + userAgent = navigator.userAgent; + } catch (error) { + console.error('Error getting user agent:', error); + } + selectedLab.userAgent = userAgent; // Make a POST request to the facilitator API - using exams endpoint for POST fetch('/facilitator/api/v1/exams/', { @@ -474,7 +481,7 @@ document.addEventListener('DOMContentLoaded', function() { } catch (error) { console.error('Error polling exam status:', error); // Show error in the loading overlay - updateLoadingMessage(`Error checking exam status: ${error.message}. Retrying in ${pollInterval/1000}s...`); + updateLoadingMessage(`Error: ${error.message}. Retrying...`); // Continue polling despite errors setTimeout(poll, pollInterval); } diff --git a/facilitator/src/services/examService.js b/facilitator/src/services/examService.js index f385bb4..4a405d6 100644 --- a/facilitator/src/services/examService.js +++ b/facilitator/src/services/examService.js @@ -66,6 +66,9 @@ async function createExam(examData) { category: examData.category, labId: examData.config.lab, examName: examData.name, + event: { + userAgent: examData.userAgent + } }); return { diff --git a/facilitator/src/utils/redisClient.js b/facilitator/src/utils/redisClient.js index 0af7ebd..9b99cc8 100644 --- a/facilitator/src/utils/redisClient.js +++ b/facilitator/src/utils/redisClient.js @@ -55,7 +55,7 @@ async function getClient() { * @param {number} [ttl=3600] - Time to live in seconds (default: 1 hour) * @returns {Promise} - Returns 'OK' if successful */ -async function persistExamInfo(examId, examInfo, ttl = 36000) { +async function persistExamInfo(examId, examInfo, ttl = 3600000) { try { const client = await getClient(); const key = `${KEYS.EXAM_INFO}${examId}`; @@ -76,7 +76,7 @@ async function persistExamInfo(examId, examInfo, ttl = 36000) { * @param {number} [ttl=3600] - Time to live in seconds (default: 1 hour) * @returns {Promise} - Returns 'OK' if successful */ -async function persistExamStatus(examId, status, ttl = 36000) { +async function persistExamStatus(examId, status, ttl = 3600000) { try { const client = await getClient(); const key = `${KEYS.EXAM_STATUS}${examId}`; @@ -96,7 +96,7 @@ async function persistExamStatus(examId, status, ttl = 36000) { * @param {number} [ttl=3600] - Time to live in seconds (default: 1 hour) * @returns {Promise} - Returns 'OK' if successful */ -async function persistExamResult(examId, result, ttl = 36000) { +async function persistExamResult(examId, result, ttl = 3600000) { try { const client = await getClient(); const key = `${KEYS.EXAM_RESULT}${examId}`; @@ -117,7 +117,7 @@ async function persistExamResult(examId, result, ttl = 36000) { * @param {number} [ttl=3600] - Time to live in seconds (default: 1 hour) * @returns {Promise} - Returns 'OK' if successful */ -async function setCurrentExamId(examId, ttl = 36000) { +async function setCurrentExamId(examId, ttl = 3600000) { try { const client = await getClient(); const result = await client.setEx(KEYS.CURRENT_EXAM_ID, ttl, examId); diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 6240f6c..8f279c0 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -333,7 +333,7 @@ try { Write-ColorOutput "CK-X Simulator has been installed in: " -NoNewline Write-ColorOutput "$(Get-Location), run all below commands from this directory" "Green" Write-ColorOutput "To stop CK-X: " -NoNewline - Write-ColorOutput "docker compose down" "Green" + Write-ColorOutput "docker compose down --volumes --remove-orphans --rmi all" "Green" Write-ColorOutput "To Restart CK-X: " -NoNewline Write-ColorOutput "docker compose restart" "Green" Write-ColorOutput "To clean up all containers and images: " -NoNewline diff --git a/scripts/install.sh b/scripts/install.sh index 0f719e0..4866ecb 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -221,7 +221,7 @@ main() { echo -e "\n${BLUE}Useful Commands${NC}" echo -e "${CYAN}==============================================================${NC}" echo -e "${YELLOW}CK-X Simulator has been installed in:${NC} ${GREEN}$(pwd)${NC}, run all below commands from this directory" - echo -e "${YELLOW}To stop CK-X ${GREEN}docker compose down${NC}" + echo -e "${YELLOW}To stop CK-X ${GREEN}docker compose down --volumes --remove-orphans --rmi all${NC}" echo -e "${YELLOW}To Restart CK-X:${NC} ${GREEN}docker compose restart${NC}" echo -e "${YELLOW}To clean up all containers and images:${NC} ${GREEN}docker system prune -a${NC}" echo -e "${YELLOW}To remove only CK-X images:${NC} ${GREEN}docker compose down --rmi all${NC}"