Search in sources :

Example 1 with TaskId

use of com.enonic.xp.task.TaskId 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 2 with TaskId

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

the class CleanUpAuditLogCommand method execute.

public TaskResultJson execute() {
    PropertyTree config = new PropertyTree();
    if (params.getAgeThreshold() != null) {
        config.addString("ageThreshold", params.getAgeThreshold());
    }
    final TaskId taskId = taskService.submitTask(SubmitTaskParams.create().descriptorKey(DescriptorKey.from("com.enonic.xp.app.system:audit-log-cleanup")).data(config).build());
    return new TaskResultJson(taskId);
}
Also used : TaskId(com.enonic.xp.task.TaskId) PropertyTree(com.enonic.xp.data.PropertyTree) TaskResultJson(com.enonic.xp.task.TaskResultJson)

Example 3 with TaskId

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

the class ContentResourceTest method reprocess_task_skip_children.

@Test
public void reprocess_task_skip_children() throws Exception {
    Content content = createContent("content-id", ContentPath.from("/path/to/content"));
    Content reprocessedContent = Content.create(content).displayName("new name").build();
    TaskId taskId = TaskId.from("task-id");
    Mockito.when(this.contentService.getByPath(content.getPath())).thenReturn(content);
    Mockito.when(this.contentService.reprocess(content.getId())).thenReturn(reprocessedContent);
    Mockito.when(this.taskService.submitTask(Mockito.any(RunnableTask.class), Mockito.anyString())).thenReturn(taskId);
    final String result = request().path("content/reprocessTask").entity(readFromFile("reprocess_params_skip_children.json"), MediaType.APPLICATION_JSON_TYPE).post().getAsString();
    assertEquals("{\"taskId\":\"task-id\"}", result);
}
Also used : TaskId(com.enonic.xp.task.TaskId) Content(com.enonic.xp.content.Content) RunnableTask(com.enonic.xp.task.RunnableTask) Test(org.junit.jupiter.api.Test)

Example 4 with TaskId

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

the class ExecuteFunctionHandler method executeFunction.

public String executeFunction() {
    final TaskService taskService = taskServiceSupplier.get();
    final TaskWrapper taskWrapper = new TaskWrapper(taskFunction, description);
    final TaskId taskId = taskService.submitTask(taskWrapper, description);
    return taskId.toString();
}
Also used : TaskId(com.enonic.xp.task.TaskId) TaskService(com.enonic.xp.task.TaskService)

Example 5 with TaskId

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

the class SubmitTaskHandler method submitTask.

public String submitTask() {
    descriptor = descriptor == null ? "" : descriptor;
    final DescriptorKey taskKey;
    if (descriptor.contains(":")) {
        taskKey = DescriptorKey.from(descriptor);
    } else {
        final ApplicationKey app = getApplication();
        if (app == null) {
            throw new RuntimeException("Could not resolve current application for descriptord task: '" + descriptor + "'");
        }
        taskKey = DescriptorKey.from(app, descriptor);
    }
    final TaskService taskService = taskServiceSupplier.get();
    PropertyTree data = propertyTreeMarshallerServiceSupplier.get().marshal(Optional.ofNullable(config).map(ScriptValue::getMap).orElse(Map.of()));
    final SubmitTaskParams params = SubmitTaskParams.create().descriptorKey(taskKey).data(data).build();
    final TaskId taskId = taskService.submitTask(params);
    return taskId.toString();
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) ScriptValue(com.enonic.xp.script.ScriptValue) TaskId(com.enonic.xp.task.TaskId) TaskService(com.enonic.xp.task.TaskService) PropertyTree(com.enonic.xp.data.PropertyTree) DescriptorKey(com.enonic.xp.page.DescriptorKey) SubmitTaskParams(com.enonic.xp.task.SubmitTaskParams)

Aggregations

TaskId (com.enonic.xp.task.TaskId)26 Test (org.junit.jupiter.api.Test)19 DescriptorKey (com.enonic.xp.page.DescriptorKey)7 TaskInfo (com.enonic.xp.task.TaskInfo)7 PropertyTree (com.enonic.xp.data.PropertyTree)6 DescribedTask (com.enonic.xp.impl.task.distributed.DescribedTask)5 TasksReporterCallable (com.enonic.xp.impl.task.distributed.TasksReporterCallable)4 TaskManager (com.enonic.xp.impl.task.distributed.TaskManager)3 User (com.enonic.xp.security.User)3 RunnableTask (com.enonic.xp.task.RunnableTask)3 SubmitTaskParams (com.enonic.xp.task.SubmitTaskParams)3 Member (com.hazelcast.core.Member)3 Instant (java.time.Instant)3 Set (java.util.Set)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)3 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)3 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)3 ApplicationKey (com.enonic.xp.app.ApplicationKey)2 Context (com.enonic.xp.context.Context)2