Search in sources :

Example 6 with TaskCommand

use of ubic.gemma.core.job.TaskCommand in project Gemma by PavlidisLab.

the class TaskRunningServiceImpl method submitLocalTask.

@Override
public <T extends Task> String submitLocalTask(T task) {
    this.checkTask(task);
    TaskCommand taskCommand = task.getTaskCommand();
    this.checkTaskCommand(taskCommand);
    final String taskId = task.getTaskCommand().getTaskId();
    if (TaskRunningServiceImpl.log.isDebugEnabled()) {
        TaskRunningServiceImpl.log.debug("Submitting local task with id: " + taskId);
    }
    final SubmittedTaskLocal submittedTask = new SubmittedTaskLocal(task.getTaskCommand(), taskPostProcessing);
    final ExecutingTask<TaskResult> executingTask = new ExecutingTask<TaskResult>(task, taskCommand);
    executingTask.setStatusCallback(new ExecutingTask.TaskLifecycleHandler() {

        @Override
        public void onFailure(Throwable e) {
            TaskRunningServiceImpl.log.error(e, e);
            submittedTask.updateStatus(SubmittedTask.Status.FAILED, new Date());
        }

        @Override
        public void onFinish() {
            submittedTask.updateStatus(SubmittedTask.Status.COMPLETED, new Date());
        }

        @Override
        public void onStart() {
            submittedTask.updateStatus(SubmittedTask.Status.RUNNING, new Date());
        }
    });
    executingTask.setProgressAppender(new LogBasedProgressAppender(taskId, new ProgressUpdateCallback() {

        private final Queue<String> progressUpdates = submittedTask.getProgressUpdates();

        @Override
        public void addProgressUpdate(String message) {
            progressUpdates.add(message);
        }
    }));
    ListenableFuture<TaskResult> future = executorService.submit(executingTask);
    submittedTask.setFuture(future);
    // Currently we have only email notification.
    if (taskCommand.isEmailAlert()) {
        submittedTask.addEmailAlert();
    }
    submittedTasks.put(taskId, submittedTask);
    return taskId;
}
Also used : Date(java.util.Date) TaskResult(ubic.gemma.core.job.TaskResult) Queue(java.util.Queue) TaskCommand(ubic.gemma.core.job.TaskCommand)

Example 7 with TaskCommand

use of ubic.gemma.core.job.TaskCommand in project Gemma by PavlidisLab.

the class ArrayDesignControllerImpl method generateSummary.

@Override
@RequestMapping("/generateArrayDesignSummary.html")
public ModelAndView generateSummary(HttpServletRequest request, HttpServletResponse response) {
    String sId = request.getParameter("id");
    // if no IDs are specified, then load all expressionExperiments and show the summary (if available)
    GenerateArraySummaryLocalTask job;
    if (StringUtils.isBlank(sId)) {
        job = new GenerateArraySummaryLocalTask(new TaskCommand());
        String taskId = taskRunningService.submitLocalTask(job);
        return new ModelAndView(new RedirectView("/arrays/showAllArrayDesigns.html", true)).addObject("taskId", taskId);
    }
    try {
        Long id = Long.parseLong(sId);
        job = new GenerateArraySummaryLocalTask(new TaskCommand(id));
        String taskId = taskRunningService.submitLocalTask(job);
        return new ModelAndView(new RedirectView("/arrays/showAllArrayDesigns.html?id=" + sId, true)).addObject("taskId", taskId);
    } catch (NumberFormatException e) {
        throw new RuntimeException("Invalid ID: " + sId);
    }
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) TaskCommand(ubic.gemma.core.job.TaskCommand) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with TaskCommand

use of ubic.gemma.core.job.TaskCommand in project Gemma by PavlidisLab.

the class ArrayDesignControllerImpl method remove.

@Override
public String remove(EntityDelegator ed) {
    ArrayDesign arrayDesign = arrayDesignService.load(ed.getId());
    if (arrayDesign == null) {
        throw new EntityNotFoundException(ed.getId() + " not found");
    }
    Collection<BioAssay> assays = arrayDesignService.getAllAssociatedBioAssays(ed.getId());
    if (assays.size() != 0) {
        throw new IllegalArgumentException("Cannot remove " + arrayDesign + ", it is used by an expression experiment");
    }
    RemoveArrayLocalTask job = new RemoveArrayLocalTask(new TaskCommand(arrayDesign.getId()));
    return taskRunningService.submitLocalTask(job);
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) EntityNotFoundException(ubic.gemma.web.util.EntityNotFoundException) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) TaskCommand(ubic.gemma.core.job.TaskCommand)

Aggregations

TaskCommand (ubic.gemma.core.job.TaskCommand)8 Test (org.junit.Test)3 BaseSpringWebTest (ubic.gemma.web.util.BaseSpringWebTest)3 List (java.util.List)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 RedirectView (org.springframework.web.servlet.view.RedirectView)2 ProgressData (ubic.gemma.core.job.progress.ProgressData)2 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)2 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)2 EntityNotFoundException (ubic.gemma.web.util.EntityNotFoundException)2 Date (java.util.Date)1 Queue (java.util.Queue)1 JMSException (javax.jms.JMSException)1 ObjectMessage (javax.jms.ObjectMessage)1 TaskResult (ubic.gemma.core.job.TaskResult)1