public void onTaskCompleted(RTask rTask, RTaskResult rTaskResult) { Console.WriteLine("DiscreteAsynchronous: onTaskCompleted: " + rTask.ToString() + ", result: " + rTaskResult.getTimeOnCall()); if (m_rBroker != null) { m_rBroker.shutdown(); Console.WriteLine("DiscreteAsynchronous: rBroker has been shutdown."); } }
public void onRuntimeStats(RBrokerRuntimeStats stats, int maxConcurrency) { RBrokerStatsHelper.printRBrokerStats(stats, maxConcurrency); if (stats.totalTasksRun == SIMULATE_TOTAL_TASK_COUNT) { Console.WriteLine("SampleAppSimulation: simulation, total time taken " + (System.Environment.TickCount - simulationStartTime) + " ms."); m_rBroker.shutdown(); Console.WriteLine("SampleAppSimulation: rBroker has been shutdown."); } }
public void onTaskCompleted(RTask rTask, RTaskResult rTaskResult) { Console.WriteLine("onTaskCompleted: " + rTask + ", result: " + rTaskResult); /* * Retrieve Job identifier from RTaskResult. */ String jobID = rTaskResult.getID(); Console.WriteLine("onTaskCompleted: " + rTask + ", background Job ID: " + jobID); if (m_rBroker != null) { /* * Important: * * To handle the results of a Background RTask you * must transition from using the RBroker Framework * API to using the .NET Client Library API. */ RUser rUser = m_rBroker.owner(); if (rUser != null) { try { RJob rJob = rUser.queryJob(jobID); Console.WriteLine("onTaskCompleted: " + rTask + ", rJob: " + rJob); /* * Next handle the result of the RJob as appropriate. * In this example, simly cancel and delete the job. */ try { rJob.cancel(); } catch (Exception cex) { Console.WriteLine("rJob.cancel ex=" + cex.ToString()); } try { rJob.delete(); } catch (Exception dex) { Console.WriteLine("rJob.delete ex=" + dex.ToString()); } } catch (Exception jex) { Console.WriteLine("rUser.queryJob ex=" + jex.ToString()); } } m_rBroker.shutdown(); Console.WriteLine("BackgroundBasics: rBroker has been shutdown."); } }
public void onRuntimeStats(RBrokerRuntimeStats stats, int maxConcurrency) { RBrokerStatsHelper.printRBrokerStats(stats, maxConcurrency); m_rBroker.shutdown(); Console.WriteLine("DiscreteProfiling: rBroker has been shutdown."); }
static public void Execute() { RBroker rBroker = null; try { /* * 1. Create RBroker instance using RBrokerFactory. * * This example creates a DiscreteTaskBroker. */ DiscreteBrokerConfig brokerConfig = new DiscreteBrokerConfig(Program.DEPLOYR_ENDPOINT); rBroker = RBrokerFactory.discreteTaskBroker(brokerConfig); /* * 2. Define RTask * * This example creates a DiscreteTask that will * execute an R script, /testuser/tutorial-rbroker/5SecondNoOp. */ RTask rTask = RTaskFactory.discreteTask(Program.TUTORIAL_NOOP_SCRIPT, Program.TUTORIAL_REPO_DIRECTORY, Program.TUTORIAL_REPO_OWNER, "", null); /* * 3. Submit RTask to RBroker for execution. * * Note, unlike an RClient.executeScript call or * an RProject.executeScript call the RBroker.submit * call is non-blocking. * * The RTaskToken is returned immediately. You can * use the token to track the progress of RTask * and/or block while waiting for a result. */ RTaskToken rTaskToken = rBroker.submit(rTask); Console.WriteLine("DiscreteBlocking: submitted " + rTask + " for execution on RBroker."); /* * 4. Demonstrate blocking for an RTask result. * * The call to getResult() will either return * an RTaskResult or raise an Exception. An Exception * indicates the RTask failed to complete and why. */ RTaskResult rTaskResult = rTaskToken.getResult(); Console.WriteLine("DiscreteBlocking: " + rTask + " completed, result=" + rTaskResult.getTimeOnCall()); } catch (Exception tex) { Console.WriteLine("DiscreteBlocking: error=" + tex.ToString()); } finally { /* * Final Step: Shutdown RBroker to release * all associated resources, connections. */ if (rBroker != null) { rBroker.shutdown(); Console.WriteLine("DiscreteBlocking: rBroker has been shutdown."); } } }