Search in sources :

Example 1 with DistributableTask

use of com.enonic.xp.impl.task.distributed.DistributableTask in project xp by enonic.

the class TaskServiceImpl method submitTask.

@Override
public TaskId submitTask(SubmitTaskParams params) {
    TaskManager taskManager;
    taskManager = clusteredTaskManagerRef.getNow(null);
    if (taskManager == null) {
        if (acceptOffloaded) {
            LOG.debug("Clustered task manager is unavailable, falling back to local task manager.");
            taskManager = localTaskManager;
        } else {
            try {
                LOG.info("Clustered task manager is unavailable, waiting...");
                taskManager = clusteredTaskManagerRef.get(5, TimeUnit.SECONDS);
            } catch (InterruptedException | TimeoutException e) {
                throw new RuntimeException(e);
            }
        }
    }
    final DistributableTask task = new DistributableTask(params.getDescriptorKey(), params.getData(), buildContext());
    taskManager.submitTask(task);
    return task.getTaskId();
}
Also used : TaskManager(com.enonic.xp.impl.task.distributed.TaskManager) DistributableTask(com.enonic.xp.impl.task.distributed.DistributableTask) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

DistributableTask (com.enonic.xp.impl.task.distributed.DistributableTask)1 TaskManager (com.enonic.xp.impl.task.distributed.TaskManager)1 TimeoutException (java.util.concurrent.TimeoutException)1