Search in sources :

Example 21 with TaskInfo

use of com.enonic.xp.task.TaskInfo in project xp by enonic.

the class TaskEventsTest method finished.

@Test
public void finished() {
    TaskInfo taskInfo = TaskInfo.create().id(TaskId.from("task1")).name("name1").description("Task1 description").application(ApplicationKey.from("com.enonic.myapp")).user(PrincipalKey.from("user:store:me")).startTime(Instant.parse("2017-10-01T09:00:00Z")).state(TaskState.FINISHED).build();
    final Event event = TaskEvents.finished(taskInfo);
    assertEquals(TaskEvents.TASK_FINISHED_EVENT, event.getType());
    assertEquals("task1", event.getValueAs(String.class, "id").get());
    assertEquals("name1", event.getValueAs(String.class, "name").get());
    assertEquals("Task1 description", event.getValueAs(String.class, "description").get());
    assertEquals("FINISHED", event.getValueAs(String.class, "state").get());
    assertEquals("com.enonic.myapp", event.getValueAs(String.class, "application").get());
    assertEquals("user:store:me", event.getValueAs(String.class, "user").get());
    assertEquals("2017-10-01T09:00:00Z", event.getValueAs(String.class, "startTime").get());
}
Also used : TaskInfo(com.enonic.xp.task.TaskInfo) Event(com.enonic.xp.event.Event) Test(org.junit.jupiter.api.Test)

Example 22 with TaskInfo

use of com.enonic.xp.task.TaskInfo in project xp by enonic.

the class GetTaskHandlerTest method testExample.

@Test
public void testExample() {
    final TaskInfo taskInfo = TaskInfo.create().state(TaskState.RUNNING).id(TaskId.from("7ca603c1-3b88-4009-8f30-46ddbcc4bb19")).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("7ca603c1-3b88-4009-8f30-46ddbcc4bb19"))).thenReturn(taskInfo);
    runScript("/lib/xp/examples/task/get.js");
}
Also used : TaskInfo(com.enonic.xp.task.TaskInfo) Test(org.junit.jupiter.api.Test)

Example 23 with TaskInfo

use of com.enonic.xp.task.TaskInfo in project xp by enonic.

the class ListTasksHandlerTest method taskList.

private List<TaskInfo> taskList() {
    final TaskInfo taskInfo1 = TaskInfo.create().state(TaskState.RUNNING).id(TaskId.from("7ca603c1-3b88-4009-8f30-46ddbcc4bb19")).description("Long running task").application(ApplicationKey.from("com.enonic.app1")).user(PrincipalKey.from("user:store:user1")).startTime(Instant.parse("2017-10-01T09:00:00Z")).progress(TaskProgress.create().current(33).total(42).info("Processing item 33").build()).build();
    final TaskInfo taskInfo2 = TaskInfo.create().state(TaskState.FINISHED).id(TaskId.from("b6173bcb-bf54-409b-aa6b-96ae6fcec263")).description("Update statistics").application(ApplicationKey.from("com.enonic.app2")).user(PrincipalKey.from("user:store:user2")).startTime(Instant.parse("2017-10-02T09:00:00Z")).progress(TaskProgress.create().info("Work completed").build()).build();
    final TaskInfo taskInfo3 = TaskInfo.create().state(TaskState.FAILED).id(TaskId.from("e1f57280-d672-4cd8-b674-98e26e5b69ae")).description("Import remote data").application(ApplicationKey.from("com.enonic.app3")).user(PrincipalKey.from("user:store:user3")).startTime(Instant.parse("2017-10-03T09:00:00Z")).progress(TaskProgress.create().current(33).total(100).info("Fetching data").build()).build();
    return Arrays.asList(taskInfo1, taskInfo2, taskInfo3);
}
Also used : TaskInfo(com.enonic.xp.task.TaskInfo)

Example 24 with TaskInfo

use of com.enonic.xp.task.TaskInfo in project xp by enonic.

the class ListTasksHandler method list.

public List<TaskMapper> list() {
    final TaskService taskService = taskServiceSupplier.get();
    final List<TaskInfo> tasks = taskService.getAllTasks();
    Stream<TaskInfo> taskStream = tasks.stream();
    if (name != null) {
        taskStream = taskStream.filter((t) -> t.getName().equals(name));
    }
    if (state != null) {
        taskStream = taskStream.filter((t) -> t.getState() == state);
    }
    return taskStream.map(TaskMapper::new).collect(Collectors.toList());
}
Also used : TaskInfo(com.enonic.xp.task.TaskInfo) BeanContext(com.enonic.xp.script.bean.BeanContext) TaskState(com.enonic.xp.task.TaskState) List(java.util.List) Stream(java.util.stream.Stream) ScriptBean(com.enonic.xp.script.bean.ScriptBean) TaskService(com.enonic.xp.task.TaskService) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) TaskInfo(com.enonic.xp.task.TaskInfo) TaskService(com.enonic.xp.task.TaskService)

Example 25 with TaskInfo

use of com.enonic.xp.task.TaskInfo in project xp by enonic.

the class GetTaskHandler method getTask.

public TaskMapper getTask() {
    final TaskService taskService = this.taskServiceSupplier.get();
    final TaskInfo taskInfo = taskService.getTaskInfo(TaskId.from(taskId));
    return taskInfo == null ? null : new TaskMapper(taskInfo);
}
Also used : TaskInfo(com.enonic.xp.task.TaskInfo) TaskService(com.enonic.xp.task.TaskService)

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