def stopWorkflow(workflowId: int): """ Stops given workflow """ res = ApiResponse(message="Error in stopping workflow") notebookIds = list( NotebookJob.objects.filter(workflow_id=workflowId).values_list( "notebookId", flat=True)) workflowRuns = WorkflowRun.objects.filter( workflow_id=workflowId).order_by("-startTimestamp") if workflowRuns.count(): workflowRun = workflowRuns[0] workflowRun.status = STATUS_ABORTED workflowRun.save() notebookIds = Workflow.objects.get( id=workflowId).notebookjob_set.all().values_list("notebookId", flat=True) responses = [ NotebookJobServices.stopNotebookJob(notebookId) for notebookId in notebookIds ] res.update(True, "Stopped workflow successfully") return res
def delete(self, request, notebookId): res = NotebookJobServices.stopNotebookJob(notebookId) return Response(res.json())