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));
}
use of com.enonic.xp.task.TaskInfo in project xp by enonic.
the class LocalTaskManagerImpl method prepareRunnable.
private Runnable prepareRunnable(final DescribedTask runnableTask) {
final TaskId id = runnableTask.getTaskId();
final User user = Objects.requireNonNullElse(runnableTask.getTaskContext().getAuthInfo().getUser(), User.ANONYMOUS);
final TaskInfo info = TaskInfo.create().id(id).description(runnableTask.getDescription()).name(runnableTask.getName()).state(TaskState.WAITING).startTime(Instant.now(clock)).application(runnableTask.getApplicationKey()).user(user.getKey()).build();
final TaskInfoHolder taskInfoHolder = TaskInfoHolder.create().taskInfo(info).build();
tasks.put(id, taskInfoHolder);
eventPublisher.publish(TaskEvents.submitted(info));
return new TaskRunnable(runnableTask, new ProgressReporterAdapter(id));
}
use of com.enonic.xp.task.TaskInfo in project xp by enonic.
the class LocalTaskManagerImpl method removeExpiredTasks.
private void removeExpiredTasks() {
final Instant now = Instant.now(clock);
for (TaskInfoHolder taskCtx : tasks.values()) {
final TaskInfo taskInfo = taskCtx.getTaskInfo();
if (taskInfo.isDone() && taskCtx.getDoneTime() != null && taskCtx.getDoneTime().until(now, ChronoUnit.SECONDS) > KEEP_COMPLETED_MAX_TIME_SEC) {
tasks.remove(taskInfo.getId());
eventPublisher.publish(TaskEvents.removed(taskInfo));
}
}
}
use of com.enonic.xp.task.TaskInfo in project xp by enonic.
the class TaskEventsTest method updated.
@Test
public void updated() {
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.RUNNING).build();
final Event event = TaskEvents.updated(taskInfo);
assertEquals(TaskEvents.TASK_UPDATED_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("RUNNING", 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());
}
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);
}
Aggregations