summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSunil Shetye2025-04-18 19:35:09 +0530
committerSunil Shetye2025-04-19 21:38:08 +0530
commitdbed4289f75875ed90eb80cbbed0f5e7b3e4faaa (patch)
treed2970c2ab9783d4d4a156439949d946011a93736
parentc4d5e944c176910fc9af68289a04b5783784f11d (diff)
downloadCommon-Interface-Project-dbed4289f75875ed90eb80cbbed0f5e7b3e4faaa.tar.gz
Common-Interface-Project-dbed4289f75875ed90eb80cbbed0f5e7b3e4faaa.tar.bz2
Common-Interface-Project-dbed4289f75875ed90eb80cbbed0f5e7b3e4faaa.zip
kill the scilab process if it is running
add isStatusDone() to check if the simulation is already complete send back the task_id also
-rw-r--r--blocks/eda-frontend/src/components/SchematicEditor/SimulationProperties.js19
-rw-r--r--blocks/eda-frontend/src/components/SchematicEditor/SimulationScreen.js72
-rw-r--r--blocks/eda-frontend/src/components/Shared/Graph.js8
-rw-r--r--blocks/simulationAPI/tasks.py10
-rw-r--r--blocks/simulationAPI/views.py8
5 files changed, 70 insertions, 47 deletions
diff --git a/blocks/eda-frontend/src/components/SchematicEditor/SimulationProperties.js b/blocks/eda-frontend/src/components/SchematicEditor/SimulationProperties.js
index 1ddbeeb2..388ae451 100644
--- a/blocks/eda-frontend/src/components/SchematicEditor/SimulationProperties.js
+++ b/blocks/eda-frontend/src/components/SchematicEditor/SimulationProperties.js
@@ -18,6 +18,7 @@ import { useSelector, useDispatch } from 'react-redux'
import { setResultTitle, setResultTaskId, resetResult } from '../../redux/simulationSlice'
import { saveXml } from './Helper/ToolbarTools'
import SimulationScreen, { setGraphStatusClosed } from './SimulationScreen'
+import { isStatusDone } from '../Shared/Graph'
import api from '../../utils/Api'
import { sanitizeTitle } from '../../utils/GalleryUtils'
@@ -75,8 +76,10 @@ export default function SimulationProperties () {
}
const handleSimulateClose = (taskId) => {
- const getUrl = 'simulation/cancel/' + taskId
- api.get(getUrl)
+ if (taskId && !isStatusDone()) {
+ const getUrl = 'simulation/cancel/' + taskId
+ api.get(getUrl)
+ }
setGraphStatusClosed()
setSimulateOpen(false)
}
@@ -96,7 +99,7 @@ export default function SimulationProperties () {
netlistConfig(file, type)
.then((response) => {
const res = response.data
- const taskId = res.details.task_id
+ const taskId = res.task_id
dispatch(setResultTaskId(taskId))
})
.catch(function (error) {
@@ -130,11 +133,11 @@ export default function SimulationProperties () {
const compNetlist = saveXml()
switch (type) {
- case 'Transient':
- dispatch(setResultTitle('Transient Analysis Output'))
- break
- default:
- break
+ case 'Transient':
+ dispatch(setResultTitle('Transient Analysis Output'))
+ break
+ default:
+ break
}
const netlist = compNetlist
diff --git a/blocks/eda-frontend/src/components/SchematicEditor/SimulationScreen.js b/blocks/eda-frontend/src/components/SchematicEditor/SimulationScreen.js
index b7739341..aff1ded7 100644
--- a/blocks/eda-frontend/src/components/SchematicEditor/SimulationScreen.js
+++ b/blocks/eda-frontend/src/components/SchematicEditor/SimulationScreen.js
@@ -6,7 +6,7 @@ import { makeStyles } from '@material-ui/core/styles'
import CloseIcon from '@material-ui/icons/Close'
import { useSelector, useDispatch } from 'react-redux'
-import Graph, { setStatusDone, setStatusClosed } from '../Shared/Graph'
+import Graph, { setStatusDone, setStatusClosed, isStatusDone } from '../Shared/Graph'
import { setResultGraph } from '../../redux/simulationSlice'
import api from '../../utils/Api'
@@ -526,7 +526,7 @@ export default function SimulationScreen ({ open, close }) {
// below code creates a html code which is table with data in that
// (To display it as matrix)
- let p = '<b>Value of Block : ' + data[lengthOfData - 1] + '-' + blockId + "</b> (Refer to label on block)<br><br><table style='width:100%'><tr>"
+ let p = `<b>Value of Block : ${data[lengthOfData - 1]}-${blockId}</b> (Refer to label on block)<br><br><table style='width:100%'><tr>`
let count = 1
for (let k = 6; k < lengthOfData - 1; k++) {
if (data[k].length !== 0) {
@@ -612,39 +612,39 @@ export default function SimulationScreen ({ open, close }) {
.get(url)
.then((res) => {
switch (res.data.state) {
- case 'PENDING':
- case 'STARTED':
- case 'RETRY':
- setIsResult(false)
- timeoutRef.current = setTimeout(() => simulationResult(url, streamingUrl), 10000)
- break
-
- case 'STREAMING':
- case 'SUCCESS':
- streamSimulationResult(streamingUrl)
- setIsResult(true)
- dispatch(setResultGraph({}))
- if (timeoutRef.current !== null) {
- clearTimeout(timeoutRef.current)
- timeoutRef.current = null
- }
- break
+ case 'PENDING':
+ case 'STARTED':
+ case 'RETRY':
+ setIsResult(false)
+ timeoutRef.current = setTimeout(() => simulationResult(url, streamingUrl), 10000)
+ break
+
+ case 'STREAMING':
+ case 'SUCCESS':
+ streamSimulationResult(streamingUrl)
+ setIsResult(true)
+ dispatch(setResultGraph({}))
+ if (timeoutRef.current !== null) {
+ clearTimeout(timeoutRef.current)
+ timeoutRef.current = null
+ }
+ break
- case 'FAILURE':
- case 'CANCELED':
- if (timeoutRef.current !== null) {
- clearTimeout(timeoutRef.current)
- timeoutRef.current = null
- }
- break
+ case 'FAILURE':
+ case 'CANCELED':
+ if (timeoutRef.current !== null) {
+ clearTimeout(timeoutRef.current)
+ timeoutRef.current = null
+ }
+ break
- default:
- console.log('unhandled case', res)
- if (timeoutRef.current !== null) {
- clearTimeout(timeoutRef.current)
- timeoutRef.current = null
- }
- break
+ default:
+ console.log('unhandled case', res)
+ if (timeoutRef.current !== null) {
+ clearTimeout(timeoutRef.current)
+ timeoutRef.current = null
+ }
+ break
}
})
.catch(function (error) {
@@ -683,12 +683,14 @@ export default function SimulationScreen ({ open, close }) {
close(taskId)
}
- window.addEventListener('beforeunload', handleTabClose)
+ if (!isStatusDone()) {
+ window.addEventListener('beforeunload', handleTabClose)
+ }
return () => {
window.removeEventListener('beforeunload', handleTabClose)
}
- }, [taskId])
+ }, [taskId, isStatusDone()])
/*
* Function to display values of all affich blocks
diff --git a/blocks/eda-frontend/src/components/Shared/Graph.js b/blocks/eda-frontend/src/components/Shared/Graph.js
index 1a230716..f0efd327 100644
--- a/blocks/eda-frontend/src/components/Shared/Graph.js
+++ b/blocks/eda-frontend/src/components/Shared/Graph.js
@@ -15,6 +15,14 @@ export function setStatusClosed () {
statusClosed = true
}
+export function isStatusDone () {
+ return statusDone
+}
+
+export function isStatusClosed () {
+ return statusClosed
+}
+
class Graph extends Component {
pointList = new Queue()
diff --git a/blocks/simulationAPI/tasks.py b/blocks/simulationAPI/tasks.py
index 4c7e57e6..3a54141d 100644
--- a/blocks/simulationAPI/tasks.py
+++ b/blocks/simulationAPI/tasks.py
@@ -7,7 +7,7 @@ from threading import current_thread
from blocks.celery_tasks import app
from simulationAPI.helpers.ngspice_helper import ExecXml, update_task_status
from simulationAPI.models import Task
-from simulationAPI.helpers.scilab_manager import uploadscript, getscriptoutput
+from simulationAPI.helpers.scilab_manager import uploadscript, getscriptoutput, kill_scilab
logger = get_task_logger(__name__)
@@ -73,3 +73,11 @@ def process_task(self, task_id):
finally:
release_lock(lock) # Ensure lock is always released
+
+
+@shared_task(bind=True)
+def kill_task(self, task_id):
+ task = Task.objects.get(task_id=task_id)
+ logger.info("Killing task %s", task)
+ kill_scilab(None, task.session, task)
+ return True
diff --git a/blocks/simulationAPI/views.py b/blocks/simulationAPI/views.py
index 0908c3f1..279b9a5e 100644
--- a/blocks/simulationAPI/views.py
+++ b/blocks/simulationAPI/views.py
@@ -16,7 +16,7 @@ from blocks.celery_tasks import app
from simulationAPI.models import Task, Session
from simulationAPI.negotiation import IgnoreClientContentNegotiation
from simulationAPI.serializers import TaskSerializer
-from simulationAPI.tasks import process_task
+from simulationAPI.tasks import process_task, kill_task
from simulationAPI.helpers.ngspice_helper import CreateXcos, update_task_status
@@ -86,8 +86,9 @@ class XmlUploader(APIView):
kwargs={'task_id': str(task_id)}, task_id=str(task_id))
if task_type == 'XCOS':
response_data = {
+ 'task_id': task_id,
'state': celery_task.state,
- 'details': serializer.data,
+ 'details': str(celery_task.info),
}
else:
rv = celery_task.get(timeout=10)
@@ -188,7 +189,8 @@ class CancelTaskView(APIView):
task_id = str(task_id)
# Cancel the task
- app.control.revoke(task_id, terminate=True)
+ app.control.revoke(task_id)
+ kill_task.delay(task_id)
# Check if task was actually revoked
celery_result = AsyncResult(task_id)