def runNotebookJob(notebookId: str, runStatusId: int = None, runType: str = "Scheduled"): """ Celery task to run a zeppelin notebook :param notebookId: ID of the zeppelin notebook which to run :param runStatusId: ID of genie.runStatus model """ if not runStatusId: runStatus = RunStatus.objects.create(notebookId=notebookId, status=NOTEBOOK_STATUS_RUNNING, runType=runType) else: runStatus = RunStatus.objects.get(id=runStatusId) runStatus.startTimestamp = dt.datetime.now() runStatus.save() try: # Check if notebook is already running isRunning, notebookName = checkIfNotebookRunning(notebookId) if (isRunning): runStatus.status = NOTEBOOK_STATUS_ERROR runStatus.message = "Notebook already running" runStatus.save() else: # Clear notebook results Zeppelin.clearNotebookResults(notebookId) response = Zeppelin.runNotebookJob(notebookId) if response: try: polling.poll(lambda: checkIfNotebookRunningAndStoreLogs( notebookId, runStatus) != True, step=3, timeout=3600) except Exception as ex: runStatus.status = NOTEBOOK_STATUS_ERROR runStatus.message = str(ex) runStatus.save() NotificationServices.notify(notebookName=notebookName, isSuccess=False, message=str(ex)) else: runStatus.status = NOTEBOOK_STATUS_ERROR runStatus.message = "Failed running notebook" runStatus.save() except Exception as ex: runStatus.status = NOTEBOOK_STATUS_ERROR runStatus.message = str(ex) runStatus.save() NotificationServices.notify(notebookName=notebookName, isSuccess=False, message=str(ex))
def runNotebookJob(notebookId: str, runType: str = "Scheduled"): """ Celery task to run a zeppelin notebook :param notebookId: ID of the zeppelin notebook which to run """ runStatus = RunStatus.objects.create(notebookId=notebookId, status="RUNNING", runType=runType) try: # Check if notebook is already running isRunning, notebookName = checkIfNotebookRunning(notebookId) if (isRunning): runStatus.status = "ERROR" runStatus.message = "Notebook already running" runStatus.save() else: # Clear noteook results Zeppelin.clearNotebookResults(notebookId) response = Zeppelin.runNotebookJob(notebookId) if response: try: polling.poll(lambda: checkIfNotebookRunningAndStoreLogs( notebookId, runStatus) != True, step=3, timeout=3600) except Exception as ex: runStatus.status = "ERROR" runStatus.message = str(ex) runStatus.save() NotificationServices.notify(notebookName=notebookName, isSuccess=False, message=str(ex)) else: runStatus.status = "ERROR" runStatus.message = "Failed running notebook" runStatus.save() except Exception as ex: runStatus.status = "ERROR" runStatus.message = str(ex) runStatus.save() NotificationServices.notify(notebookName=notebookName, isSuccess=False, message=str(ex))