Search in sources :

Example 1 with TaskCallable

use of com.baidu.hugegraph.task.TaskCallable in project incubator-hugegraph by apache.

the class JobBuilder method schedule.

public HugeTask<V> schedule() {
    E.checkArgumentNotNull(this.name, "Job name can't be null");
    E.checkArgumentNotNull(this.job, "Job callable can't be null");
    E.checkArgument(this.job instanceof TaskCallable, "Job must be instance of TaskCallable");
    this.graph.taskScheduler().checkRequirement("schedule");
    @SuppressWarnings("unchecked") TaskCallable<V> job = (TaskCallable<V>) this.job;
    HugeTask<V> task = new HugeTask<>(this.genTaskId(), null, job);
    task.type(this.job.type());
    task.name(this.name);
    if (this.input != null) {
        task.input(this.input);
    }
    if (this.dependencies != null && !this.dependencies.isEmpty()) {
        for (Id depend : this.dependencies) {
            task.depends(depend);
        }
    }
    TaskScheduler scheduler = this.graph.taskScheduler();
    scheduler.schedule(task);
    return task;
}
Also used : HugeTask(com.baidu.hugegraph.task.HugeTask) Id(com.baidu.hugegraph.backend.id.Id) TaskScheduler(com.baidu.hugegraph.task.TaskScheduler) TaskCallable(com.baidu.hugegraph.task.TaskCallable)

Example 2 with TaskCallable

use of com.baidu.hugegraph.task.TaskCallable in project incubator-hugegraph by apache.

the class TaskCoreTest method testTaskWithFailure.

@Test
public void testTaskWithFailure() throws TimeoutException {
    HugeGraph graph = graph();
    TaskScheduler scheduler = graph.taskScheduler();
    TaskCallable<Integer> callable = new TaskCallable<Integer>() {

        @Override
        public Integer call() throws Exception {
            sleepAWhile();
            return 125;
        }

        @Override
        protected void done() {
            scheduler.save(this.task());
        }
    };
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        new HugeTask<>(null, null, callable);
    }, e -> {
        Assert.assertContains("Task id can't be null", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Id id = IdGenerator.of("88888");
        new HugeTask<>(id, null, callable);
    }, e -> {
        Assert.assertContains("Invalid task id type, it must be number", e.getMessage());
    });
    Assert.assertThrows(NullPointerException.class, () -> {
        Id id = IdGenerator.of(88888);
        new HugeTask<>(id, null, null);
    });
    Assert.assertThrows(IllegalStateException.class, () -> {
        Id id = IdGenerator.of(88888);
        HugeTask<?> task2 = new HugeTask<>(id, null, callable);
        task2.name("test-task");
        scheduler.schedule(task2);
    }, e -> {
        Assert.assertContains("Task type can't be null", e.getMessage());
    });
    Assert.assertThrows(IllegalStateException.class, () -> {
        Id id = IdGenerator.of(88888);
        HugeTask<?> task2 = new HugeTask<>(id, null, callable);
        task2.type("test");
        scheduler.schedule(task2);
    }, e -> {
        Assert.assertContains("Task name can't be null", e.getMessage());
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeTask(com.baidu.hugegraph.task.HugeTask) Id(com.baidu.hugegraph.backend.id.Id) TaskScheduler(com.baidu.hugegraph.task.TaskScheduler) TaskCallable(com.baidu.hugegraph.task.TaskCallable) Test(org.junit.Test)

Aggregations

Id (com.baidu.hugegraph.backend.id.Id)2 HugeTask (com.baidu.hugegraph.task.HugeTask)2 TaskCallable (com.baidu.hugegraph.task.TaskCallable)2 TaskScheduler (com.baidu.hugegraph.task.TaskScheduler)2 HugeGraph (com.baidu.hugegraph.HugeGraph)1 Test (org.junit.Test)1