public RTaskResult call()

in src/main/java/com/revo/deployr/client/broker/worker/DiscreteTaskWorker.java [54:156]


    public RTaskResult call() throws RClientException,
            RSecurityException,
            RDataException,
            RGridException {

        RTaskResult taskResult = null;

        long timeOnCall = 0L;
        long timeOnServer = 0L;

        try {

            AnonymousProjectExecutionOptions options =
                    ROptionsTranslator.translate(task.options);

            long startTime = System.currentTimeMillis();

            RScriptExecution execResult = null;

            if (task.external != null) {
                execResult = rClient.executeExternal(task.external,
                        options);
            } else {
                execResult = rClient.executeScript(task.filename,
                        task.directory,
                        task.author,
                        task.version,
                        options);
            }

            timeOnCall = System.currentTimeMillis() - startTime;

            String generatedConsole = execResult.about().console;

            List<URL> generatedPlots = new ArrayList<URL>();
            if (execResult.about().results != null) {
                for (RProjectResult result : execResult.about().results) {
                    generatedPlots.add(result.about().url);
                }
            }

            List<URL> generatedFiles = new ArrayList<URL>();
            if (execResult.about().artifacts != null) {
                for (RProjectFile artifact : execResult.about().artifacts) {
                    // generatedFiles.add(artifact.download());
                    generatedFiles.add(artifact.about().url);
                }
            }

            List<RData> generatedObjects = execResult.about().workspaceObjects;

            List<URL> storedFiles = new ArrayList<URL>();
            if (execResult.about().repositoryFiles != null) {
                for (RRepositoryFile repoFile : execResult.about().repositoryFiles) {
                    // storedFiles.add(repoFile.download());
                    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() instanceof 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.
             */
            rBroker.callback(task, taskResult);
        }

        return taskResult;

    }