use of com.enonic.xp.task.TaskInfo in project xp by enonic.
the class ListTasksHandlerTest method testExample.
@Test
public void testExample() {
final TaskInfo taskInfo = TaskInfo.create().state(TaskState.RUNNING).id(TaskId.from("7ca603c1-3b88-4009-8f30-46ddbcc4bb19")).name("com.enonic.myapp:clean-up").description("Long running task").application(ApplicationKey.from("com.enonic.myapp")).user(PrincipalKey.from("user:store:user")).startTime(Instant.parse("2017-10-01T09:00:00Z")).progress(TaskProgress.create().current(33).total(42).info("Processing item 33").build()).build();
Mockito.when(this.taskService.getAllTasks()).thenReturn(taskList()).thenReturn(Collections.singletonList(taskInfo));
runScript("/lib/xp/examples/task/list.js");
}
use of com.enonic.xp.task.TaskInfo in project xp by enonic.
the class IsRunningHandlerTest method testExample.
@Test
public void testExample() {
final TaskInfo taskInfo = TaskInfo.create().state(TaskState.RUNNING).id(TaskId.from("7ca603c1-3b88-4009-8f30-46ddbcc4bb19")).name("com.enonic.myapp:clean-up-task").description("Long running task").progress(TaskProgress.create().current(33).total(42).info("Processing item 33").build()).build();
Mockito.when(this.taskService.getRunningTasks()).thenReturn(Collections.singletonList(taskInfo));
runScript("/lib/xp/examples/task/isRunning.js");
}
use of com.enonic.xp.task.TaskInfo in project xp by enonic.
the class TaskResource method getTask.
@GET
@Path("/{taskId}")
public TaskInfoJson getTask(@PathParam("taskId") final String taskIdString) {
final TaskId taskId = TaskId.from(taskIdString);
final TaskInfo taskInfo = taskService.getTaskInfo(taskId);
if (taskInfo == null) {
throw new WebApplicationException(String.format("Task [%s] was not found", taskIdString), Response.Status.NOT_FOUND);
}
return new TaskInfoJson(taskInfo);
}
use of com.enonic.xp.task.TaskInfo in project xp by enonic.
the class GetTaskHandlerTest method testGetTaskExisting.
@Test
public void testGetTaskExisting() throws Exception {
final TaskInfo taskInfo = TaskInfo.create().state(TaskState.RUNNING).id(TaskId.from("123")).description("Long running task").application(ApplicationKey.from("com.enonic.myapp")).user(PrincipalKey.from("user:store:me")).startTime(Instant.parse("2017-10-01T09:00:00Z")).progress(TaskProgress.create().current(33).total(42).info("Processing item 33").build()).build();
Mockito.when(this.taskService.getTaskInfo(TaskId.from("123"))).thenReturn(taskInfo);
runFunction("/test/get-test.js", "getExistingTask");
}
use of com.enonic.xp.task.TaskInfo in project xp by enonic.
the class LocalTaskManagerImpl method updateProgress.
private void updateProgress(final TaskId taskId, final String message) {
final TaskInfoHolder ctx = tasks.get(taskId);
if (ctx == null) {
return;
}
final TaskInfo taskInfo = ctx.getTaskInfo();
final TaskProgress updatedProgress = taskInfo.getProgress().copy().info(message).build();
final TaskInfo updatedInfo = taskInfo.copy().progress(updatedProgress).build();
final TaskInfoHolder updatedCtx = ctx.copy().taskInfo(updatedInfo).build();
tasks.put(taskId, updatedCtx);
eventPublisher.publish(TaskEvents.updated(updatedInfo));
}
Aggregations