/// <summary> /// Run the acutal discrete task using Project API /// </summary> /// <returns>Results of the pooled task</returns> /// <remarks></remarks> public RTaskResult call() { RTaskResult taskResult = null; long timeOnCall = 0L; //long timeOnServer = 0L; try { ProjectExecutionOptions options = ROptionsTranslator.translate(m_task.options); long startTime = Environment.TickCount; RProjectExecution execResult = m_rProject.executeScript(m_task.filename, m_task.directory, m_task.author, m_task.version, options); timeOnCall = Environment.TickCount - startTime; String generatedConsole = execResult.about().console; List <String> generatedPlots = new List <String>(); if (execResult.about().results != null) { foreach (RProjectResult result in execResult.about().results) { generatedPlots.Add(result.about().url); } } List <String> generatedFiles = new List <String>(); if (execResult.about().artifacts != null) { foreach (RProjectFile artifact in execResult.about().artifacts) { generatedFiles.Add(artifact.about().url); } } List <RData> generatedObjects = execResult.about().workspaceObjects; List <String> storedFiles = new List <String>(); if (execResult.about().repositoryFiles != null) { foreach (RRepositoryFile repoFile in execResult.about().repositoryFiles) { storedFiles.Add(repoFile.about().url); } } taskResult = new RTaskResultImpl(execResult.about().id, RTaskType.POOLED, true, execResult.about().timeCode, execResult.about().timeTotal, timeOnCall, null, false, generatedConsole, generatedPlots, generatedFiles, generatedObjects, storedFiles); } catch (Exception ex) { //if(ex.getCause() instanceof InterruptedException) //{ try { /* * If RTaskToken.cancel() raises InterruptedException * then ensure any corresponding execution on RProject is * also cancelled. */ m_rProject.interruptExecution(); } catch (Exception iex) { throw new Exception("Project cancel Exception occurred: " + iex.ToString()); } //} taskResult = new RTaskResultImpl(null, RTaskType.POOLED, false, 0L, 0L, 0L, ex); } finally { /* * Callback to PooledTaskBroker to release * RProject back into pool for other tasks. */ m_rBroker.callback(m_task, taskResult); } return(taskResult); }
/// <summary> /// Run the acutal discrete task using Project API /// </summary> /// <returns>Results of the pooled task</returns> /// <remarks></remarks> public RTaskResult call() { RTaskResult taskResult = null; long timeOnCall = 0L; //long timeOnServer = 0L; try { ProjectExecutionOptions options = ROptionsTranslator.translate(m_task.options); long startTime = Environment.TickCount; RProjectExecution execResult = m_rProject.executeScript(m_task.filename, m_task.directory, m_task.author, m_task.version, options); timeOnCall = Environment.TickCount - startTime; String generatedConsole = execResult.about().console; List<String> generatedPlots = new List<String>(); if(execResult.about().results != null) { foreach(RProjectResult result in execResult.about().results) { generatedPlots.Add(result.about().url); } } List<String> generatedFiles = new List<String>(); if(execResult.about().artifacts != null) { foreach(RProjectFile artifact in execResult.about().artifacts) { generatedFiles.Add(artifact.about().url); } } List<RData> generatedObjects = execResult.about().workspaceObjects; List<String> storedFiles = new List<String>(); if(execResult.about().repositoryFiles != null) { foreach(RRepositoryFile repoFile in execResult.about().repositoryFiles) { storedFiles.Add(repoFile.about().url); } } taskResult = new RTaskResultImpl(execResult.about().id, RTaskType.POOLED, true, execResult.about().timeCode, execResult.about().timeTotal, timeOnCall, null, false, generatedConsole, generatedPlots, generatedFiles, generatedObjects, storedFiles); } catch (Exception ex) { //if(ex.getCause() instanceof InterruptedException) //{ try { /* * If RTaskToken.cancel() raises InterruptedException * then ensure any corresponding execution on RProject is * also cancelled. */ m_rProject.interruptExecution(); } catch(Exception iex) { throw new Exception("Project cancel Exception occurred: " + iex.ToString()); } //} taskResult = new RTaskResultImpl(null, RTaskType.POOLED, false, 0L, 0L, 0L, ex); } finally { /* * Callback to PooledTaskBroker to release * RProject back into pool for other tasks. */ m_rBroker.callback(m_task, taskResult); } return taskResult; }
/// <summary> /// Run the acutal background task using Job API /// </summary> /// <returns>Results of the background task</returns> /// <remarks></remarks> public RTaskResult call() { RTaskResult taskResult = null; RJob rJob = null; long timeOnCall = 0L; //long timeOnServer = 0L; try { long startTime = Environment.TickCount; JobExecutionOptions options = ROptionsTranslator.translate(m_task.options, m_isPriorityTask); if(m_task.code != "") { rJob = m_rUser.submitJobCode(m_task.name, m_task.description, m_task.code, options); } else { if(m_task.external != "") { rJob = m_rUser.submitJobExternal(m_task.external, m_task.description, m_task.code, options); } else { rJob = m_rUser.submitJobScript(m_task.name, m_task.description, m_task.filename, m_task.directory, m_task.author, m_task.version, options); } } timeOnCall = Environment.TickCount - startTime; taskResult = new RTaskResultImpl(rJob.about().id, RTaskType.BACKGROUND, true, 0L, 0L, timeOnCall, null); } catch (Exception ex) { //if(ex. instanceof InterruptedException) //{ try { /* * If RTaskToken.cancel() call raises InterruptedException * then ensure any corresponding scheduled RJob is * also cancelled. */ rJob.cancel(); } catch(Exception iex) { throw new Exception("RBroker: could not cancel job, cause: " + iex.ToString()); } //} taskResult = new RTaskResultImpl(null, RTaskType.BACKGROUND, false, 0L, 0L, 0L, ex); } finally { /* * Callback to PooledTaskBroker to release * RProject back into pool for other tasks. */ m_rBroker.callback(m_task, taskResult); } return taskResult; }
/// <summary> /// Returns a resource token for the task back to the token pool. /// </summary> /// <param name="task">RTask submitted for execution as a background task</param> /// <param name="result">RTaskResult containing the results of the completed task</param> /// <remarks></remarks> public override void callback(RTask task, RTaskResult result) { Object obj; m_taskResourceTokenMap.TryGetValue(task, out obj); RProject rProject = (RProject)obj; /* * Check for Grid Exception */ Boolean bGridException = false; Exception failure = result.getFailure(); if (failure != null) { if (failure.GetType() == typeof(HTTPRestException)) { HTTPRestException ex = (HTTPRestException)failure; if (ex.errorCode >= 910 || ex.errorCode == 403) { bGridException = true; } } } if (bGridException == true) { /* * On detection of an RGridException drop the RProject from * the pool so further tasks are not directed to that RProject. * We achieve this by simply not adding the RProject back to the * resourceTokenPool on this callback. * * We then need to adjust the parallelTaskLimit so the RBroker * will report the new (smaller) pool size on * RBroker.maxConcurrency() calls. */ if (m_taskListener != null) { /* * When asynchronous listener in use, failed task * executions due to slot or grid failures can be * automatically resubmitted for execution by the RBroker. * * When RTaskResult.repeatTask is enabled the * RBrokerEngine.RBrokerListenerManager will skip * calling taskListener.onTaskCompleted(task, result). * This prevents a client application from seeing * (or having to handle) temporary slot or grid related * failures on RTasks. */ RTaskResultImpl resultImpl = (RTaskResultImpl)result; resultImpl.repeatTask = true; /* * Now re-submit for execution using the priority * queue to expedite processing. */ try { submit(task, true); } catch (Exception tex) { throw new Exception("PooledTaskBroker: callback, task re-submission ex=" + tex.ToString()); } } int resizedPoolSize = (int)Interlocked.Decrement(ref m_parallelTaskLimit); if (m_brokerListener != null) { Exception rbex; if (resizedPoolSize == 0) { rbex = new Exception("DeployR grid failure detected, pool no longer operational, advise RBroker shutdown."); } else { rbex = new Exception("DeployR grid failure detected, pool size auto-adjusted, max concurrency now " + resizedPoolSize + "."); } m_brokerListener.onRuntimeError(rbex.Message); } } else { if (rProject != null) { Boolean added = m_resourceTokenPool.TryAdd(rProject); if (!added) { throw new Exception("PooledTaskBroker: callback, project could not be added back to pool?"); } } else { throw new Exception("PooledTaskBroker: callback, task does not have matching project?"); } } }
/// <summary> /// Run the acutal discrete task using Client API /// </summary> /// <returns>Results of the discrete task</returns> /// <remarks></remarks> public RTaskResult call() { RTaskResult taskResult = null; long timeOnCall = 0L; //long timeOnServer = 0L; try { AnonymousProjectExecutionOptions options = ROptionsTranslator.translate(m_task.options); long startTime = Environment.TickCount; RScriptExecution execResult = m_rClient.executeScript(m_task.filename, m_task.directory, m_task.author, m_task.version, options); timeOnCall = Environment.TickCount - startTime; String generatedConsole = execResult.about().console; List <String> generatedPlots = new List <String>(); if (execResult.about().results != null) { foreach (RProjectResult result in execResult.about().results) { generatedPlots.Add(result.about().url); } } List <String> generatedFiles = new List <String>(); if (execResult.about().artifacts != null) { foreach (RProjectFile artifact in execResult.about().artifacts) { generatedFiles.Add(artifact.about().url); } } List <RData> generatedObjects = execResult.about().workspaceObjects; List <String> storedFiles = new List <String>(); if (execResult.about().repositoryFiles != null) { foreach (RRepositoryFile repoFile in execResult.about().repositoryFiles) { storedFiles.Add(repoFile.about().url); } } taskResult = new RTaskResultImpl(execResult.about().id, RTaskType.DISCRETE, true, execResult.about().timeCode, execResult.about().timeTotal, timeOnCall, null, false, generatedConsole, generatedPlots, generatedFiles, generatedObjects, storedFiles); } catch (Exception ex) { //if(ex.getCause() == typeof(InterruptedException)) //{ /* * RTaskToken.cancel() can raise an InterruptedException. * When an InterruptedException is detected the DiscreteTask * executing on the server should be aborted at this point. * However, there is no way to obtain DeployR reference, such * as a projectId, for an stateless execution in-progress, so * aborting the current RTask operation is not possible. */ //} taskResult = new RTaskResultImpl(null, RTaskType.DISCRETE, false, 0L, 0L, 0L, ex); } finally { /* * Callback to PooledTaskBroker to release * RProject back into pool for other tasks. */ m_rBroker.callback(m_task, taskResult); } return(taskResult); }
/// <summary> /// Run the acutal background task using Job API /// </summary> /// <returns>Results of the background task</returns> /// <remarks></remarks> public RTaskResult call() { RTaskResult taskResult = null; RJob rJob = null; long timeOnCall = 0L; //long timeOnServer = 0L; try { long startTime = Environment.TickCount; JobExecutionOptions options = ROptionsTranslator.translate(m_task.options, m_isPriorityTask); if(m_task.code != "") { rJob = m_rUser.submitJobCode(m_task.name, m_task.description, m_task.code, options); } else { if(m_task.external != "") { rJob = m_rUser.submitJobExternal(m_task.external, m_task.description, m_task.code, options); } else { rJob = m_rUser.submitJobScript(m_task.name, m_task.description, m_task.filename, m_task.directory, m_task.author, m_task.version, options); } } timeOnCall = Environment.TickCount - startTime; taskResult = new RTaskResultImpl(rJob.about().id, RTaskType.BACKGROUND, true, 0L, 0L, timeOnCall, null); } catch (Exception ex) { //if(ex. instanceof InterruptedException) //{ try { /* * If RTaskToken.cancel() call raises InterruptedException * then ensure any corresponding scheduled RJob is * also cancelled. */ rJob.cancel(); } catch(Exception iex) { throw new Exception("RBroker: could not cancel job, cause: " + iex.ToString()); } //} taskResult = new RTaskResultImpl(null, RTaskType.BACKGROUND, false, 0L, 0L, 0L, ex); } finally { /* * Callback to PooledTaskBroker to release * RProject back into pool for other tasks. */ m_rBroker.callback(m_task, taskResult); } return taskResult; }
/// <summary> /// Run the acutal discrete task using Client API /// </summary> /// <returns>Results of the discrete task</returns> /// <remarks></remarks> public RTaskResult call() { RTaskResult taskResult = null; long timeOnCall = 0L; //long timeOnServer = 0L; try { AnonymousProjectExecutionOptions options = ROptionsTranslator.translate(m_task.options); long startTime = Environment.TickCount; RScriptExecution execResult = m_rClient.executeScript(m_task.filename, m_task.directory, m_task.author, m_task.version, options); timeOnCall = Environment.TickCount - startTime; String generatedConsole = execResult.about().console; List<String> generatedPlots = new List<String>(); if(execResult.about().results != null) { foreach(RProjectResult result in execResult.about().results) { generatedPlots.Add(result.about().url); } } List<String> generatedFiles = new List<String>(); if(execResult.about().artifacts != null) { foreach(RProjectFile artifact in execResult.about().artifacts) { generatedFiles.Add(artifact.about().url); } } List<RData> generatedObjects = execResult.about().workspaceObjects; List<String> storedFiles = new List<String>(); if(execResult.about().repositoryFiles != null) { foreach(RRepositoryFile repoFile in execResult.about().repositoryFiles) { storedFiles.Add(repoFile.about().url); } } taskResult = new RTaskResultImpl(execResult.about().id, RTaskType.DISCRETE, true, execResult.about().timeCode, execResult.about().timeTotal, timeOnCall, null, false, generatedConsole, generatedPlots, generatedFiles, generatedObjects, storedFiles); } catch (Exception ex) { //if(ex.getCause() == typeof(InterruptedException)) //{ /* * RTaskToken.cancel() can raise an InterruptedException. * When an InterruptedException is detected the DiscreteTask * executing on the server should be aborted at this point. * However, there is no way to obtain DeployR reference, such * as a projectId, for an stateless execution in-progress, so * aborting the current RTask operation is not possible. */ //} taskResult = new RTaskResultImpl(null, RTaskType.DISCRETE, false, 0L, 0L, 0L, ex); } finally { /* * Callback to PooledTaskBroker to release * RProject back into pool for other tasks. */ m_rBroker.callback(m_task, taskResult); } return taskResult; }