use of com.enonic.xp.task.TaskService in project xp by enonic.
the class ContentResourceTest method getResourceInstance.
@Override
protected Object getResourceInstance() {
this.contentService = Mockito.mock(ContentService.class);
this.taskService = Mockito.mock(TaskService.class);
final ProjectService projectService = Mockito.mock(ProjectService.class);
final SyncContentService syncContentService = Mockito.mock(SyncContentService.class);
final ContentResource resource = new ContentResource();
resource.setContentService(contentService);
resource.setTaskService(taskService);
resource.setProjectService(projectService);
resource.setSyncContentService(syncContentService);
return resource;
}
use of com.enonic.xp.task.TaskService 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();
}
use of com.enonic.xp.task.TaskService 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();
}
use of com.enonic.xp.task.TaskService in project xp by enonic.
the class SubmitTaskHandlerTest method initialize.
@Override
public void initialize() throws Exception {
super.initialize();
taskService = Mockito.mock(TaskService.class);
addService(TaskService.class, taskService);
final TaskDescriptorService taskDescriptorService = Mockito.mock(TaskDescriptorService.class);
addService(TaskDescriptorService.class, taskDescriptorService);
final MixinService mixinService = Mockito.mock(MixinService.class);
addService(MixinService.class, mixinService);
final Form cfg1 = Form.create().addFormItem(Input.create().name("count").label("Count").inputType(InputTypeName.LONG).required(true).build()).build();
final Form cfg2 = Form.create().addFormItem(Input.create().name("values").label("Values").inputType(InputTypeName.TEXT_LINE).required(true).multiple(true).build()).build();
final TaskDescriptor desc1 = TaskDescriptor.create().key(DescriptorKey.from("myapplication:job42")).config(cfg1).build();
final TaskDescriptor desc2 = TaskDescriptor.create().key(DescriptorKey.from("myapplication:my-task")).config(cfg2).build();
final TaskDescriptor desc3 = TaskDescriptor.create().key(DescriptorKey.from("other-app:some-task")).build();
Mockito.when(taskDescriptorService.getTasks()).thenReturn(Descriptors.from(desc1, desc2, desc3));
Mockito.when(mixinService.inlineFormItems(any(Form.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
addService(PropertyTreeMarshallerService.class, PropertyTreeMarshallerServiceFactory.newInstance(mixinService));
}
use of com.enonic.xp.task.TaskService in project xp by enonic.
the class SchedulableTaskImpl method run.
@Override
public void run() {
try {
final TaskId taskId = taskContext().callWith(() -> OsgiSupport.withService(TaskService.class, taskService -> taskService.submitTask(SubmitTaskParams.create().descriptorKey(job.getDescriptor()).data(job.getConfig()).build())));
adminContext().runWith(() -> OsgiSupport.withService(NodeService.class, nodeService -> UpdateLastRunCommand.create().nodeService(nodeService).name(job.getName()).lastRun(Instant.now()).lastTaskId(taskId).build().execute()));
} catch (Exception e) {
LOG.warn("Error while running job [{}]", this.job.getName(), e);
} catch (Throwable t) {
LOG.error("Error while running job [{}], no further attempts will be made", this.job.getName(), t);
throw t;
}
}
Aggregations