static public void Execute() { Console.WriteLine("AuthJobStoreResultToRepository - start"); // // 1. Connect to the DeployR Server // RClient rClient = Utility.Connect(); // // 2. Authenticate the user // RUser rUser = Utility.Authenticate(rClient); // // 3. Submit a background job to execute a block of R code // that will generate a vector object. We will then use // JobExecutionOtpions to request the following behavior: // // a. Execute the job at low (default) priority. // b. Skip the persistence of results to a project. // c. Request the persistence of a named vector object // as a binary R object file to the repository. // String rCode = "tutorialVector <- rnorm(100)"; JobExecutionOptions options = new JobExecutionOptions(); options.priority = JobExecutionOptions.LOW_PRIORITY; options.noProject = true; // // 4. Use ProjectStorageOptions to identify the name of one // or more workspace objects for storage to the repository. // // In this case, the named object matches the name of the // object created the rCode being executed on the job. We // request that the binary R object file be stored into // the root directory in the repository. // options.storageOptions = new ProjectStorageOptions(); options.storageOptions.objects = "tutorialVector"; options.storageOptions.directory = "root"; RJob rJob = rUser.submitJobCode("Background Code Execution", "Demonstrate storing job results to repository.", rCode, options); Console.WriteLine("AuthJobStoreResultToRepository: submitted background job " + "for execution, rJob=" + rJob); // // 5. Query the execution status of a background job and loop until the job has finished // if (rJob != null) { while (true) { String sMsg = rJob.query().status.Value; if (sMsg == RJob.Status.COMPLETED.Value | sMsg == RJob.Status.FAILED.Value | sMsg == RJob.Status.CANCELLED.Value | sMsg == RJob.Status.ABORTED.Value) { break; } else { Thread.Sleep(500); } } } // // 6. Retrieve the RepositoryFile from completed job // RRepositoryFile rRepositoryFile = null; if (rJob != null) { // // 7. Retrieve the results of the background job // execution. Given the custom JobExecutionOptions // specified for this job (noproject=true) there will // be no RProject to hold the results. // // However, the custom JobExecutionOptions specified // for this job requested the storage of the // "tutorialVector" vector object as a binary R // object file (.rData) in the repository. // // The following code demonstrates how we can // retrieve that result from the repository: // String sUserName = rUser.about().Username; rRepositoryFile = rUser.fetchFile("tutorialVector.rData", sUserName, "root", ""); Console.WriteLine("AuthJobStoreResultToRepository: retrieved background " + "job result from repository, rRepositoryFile=" + rRepositoryFile); } // // 8. Cleanup // if (rRepositoryFile != null) { //rRepositoryFile.delete(); //un-comment if you wish to delete the RepositoryFile } if (rJob != null) { //rJob.delete(); //un-comment if you wish to delete the job } Utility.Cleanup(rUser, rClient); Console.WriteLine("AuthJobStoreResultToRepository - end"); }
static public void Execute() { Console.WriteLine("AuthJobExecuteScript - start"); // // 1. Connect to the DeployR Server // RClient rClient = Utility.Connect(); // // 2. Authenticate the user // RUser rUser = Utility.Authenticate(rClient); // // 3. Submit a background job for execution based on a // repository-managed R script: /testuser/root/Histogram of Auto Sales.R // JobExecutionOptions options = new JobExecutionOptions(); options.priority = JobExecutionOptions.HIGH_PRIORITY; //Make this a High Priority job RJob rJob = rUser.submitJobScript("Background Script Execution", "Background script execution.", "Histogram of Auto Sales", "root", "testuser", "", options); Console.WriteLine("AuthJobExecuteScript: submitted background job " + "for execution, rJob=" + rJob); // // 4. Query the execution status of a background job and loop until the job has finished // if (rJob != null) { while (true) { String sMsg = rJob.query().status.Value; if (sMsg == RJob.Status.COMPLETED.Value | sMsg == RJob.Status.FAILED.Value | sMsg == RJob.Status.CANCELLED.Value | sMsg == RJob.Status.ABORTED.Value) { break; } else { Thread.Sleep(500); } } } // // 5. Retrieve the project from completed job // RProject rProject = null; if (rJob != null) { // make sure we have a valid project id if (rJob.query().project.Length > 0) { //get the project using the project id rProject = rUser.getProject(rJob.query().project); Console.WriteLine("AuthJobExecuteScript: retrieved background " + "job result on project, rProject=" + rProject); } } // // 6. Cleanup // if (rProject != null) { rProject.close(); //rProject.delete(); //un-comment if you wish to delete the project } if (rJob != null) { //rJob.delete(); //un-comment if you wish to delete the job } Utility.Cleanup(rUser, rClient); Console.WriteLine("AuthJobExecuteScript - end"); }
static public void Execute() { Console.WriteLine("AuthJobExecuteCode - start"); // // 1. Connect to the DeployR Server // RClient rClient = Utility.Connect(); // // 2. Authenticate the user // RUser rUser = Utility.Authenticate(rClient); // // 3. Submit a background job for execution based on an // arbitrary block of R code: [codeBlock] // String codeBlock = "demo(graphics)"; JobExecutionOptions options = new JobExecutionOptions(); options.priority = JobExecutionOptions.MEDIUM_PRIORITY; //Make this a Medium Priority job RJob rJob = rUser.submitJobCode("Sample Job", "Sample description.", codeBlock, options); Console.WriteLine("AuthJobExecuteCode: submitted background job for execution, rJob=" + rJob); // // 4. Query the execution status of a background job and loop until the job has finished // if (rJob != null) { while (true) { String sMsg = rJob.query().status.Value; if (sMsg == RJob.Status.COMPLETED.Value | sMsg == RJob.Status.FAILED.Value | sMsg == RJob.Status.CANCELLED.Value | sMsg == RJob.Status.ABORTED.Value) { break; } else { Thread.Sleep(500); } } } // // 5. Retrieve the project from completed job // RProject rProject = null; if (rJob != null) { // make sure we have a valid project id if (rJob.query().project.Length > 0) { //get the project using the project id rProject = rUser.getProject(rJob.query().project); Console.WriteLine("AuthJobExecuteCode: retrieved background " + "job result on project, rProject=" + rProject); } } // // 6. Cleanup // if (rProject != null) { rProject.close(); //rProject.delete(); //un-comment if you wish to delete the project } if (rJob != null) { //rJob.delete(); //un-comment if you wish to delete the job } Utility.Cleanup(rUser, rClient); Console.WriteLine("AuthJobExecuteCode - end"); }