Search in sources :

Example 1 with TaskInfo

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");
}
Also used : TaskInfo(com.enonic.xp.task.TaskInfo) Test(org.junit.jupiter.api.Test)

Example 2 with TaskInfo

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");
}
Also used : TaskInfo(com.enonic.xp.task.TaskInfo) Test(org.junit.jupiter.api.Test)

Example 3 with TaskInfo

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);
}
Also used : TaskInfo(com.enonic.xp.task.TaskInfo) TaskInfoJson(com.enonic.xp.task.TaskInfoJson) TaskId(com.enonic.xp.task.TaskId) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 4 with 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");
}
Also used : TaskInfo(com.enonic.xp.task.TaskInfo) Test(org.junit.jupiter.api.Test)

Example 5 with TaskInfo

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));
}
Also used : TaskInfo(com.enonic.xp.task.TaskInfo) TaskProgress(com.enonic.xp.task.TaskProgress)

Aggregations

TaskInfo (com.enonic.xp.task.TaskInfo)25 Test (org.junit.jupiter.api.Test)15 TaskId (com.enonic.xp.task.TaskId)9 Event (com.enonic.xp.event.Event)6 TasksReporterCallable (com.enonic.xp.impl.task.distributed.TasksReporterCallable)5 Member (com.hazelcast.core.Member)4 Instant (java.time.Instant)3 List (java.util.List)3 TaskProgress (com.enonic.xp.task.TaskProgress)2 TaskService (com.enonic.xp.task.TaskService)2 TaskState (com.enonic.xp.task.TaskState)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 Branch (com.enonic.xp.branch.Branch)1 RecurringJob (com.enonic.xp.core.internal.concurrent.RecurringJob)1 OsgiSupportMock (com.enonic.xp.core.internal.osgi.OsgiSupportMock)1 AllTasksReporter (com.enonic.xp.impl.task.distributed.AllTasksReporter)1 DescribedTask (com.enonic.xp.impl.task.distributed.DescribedTask)1