class TaskExample {

    private static final Logger LOG = Log.logger(TaskExample.class);

    public static void main(String[] args) throws Exception {
        LOG.info("TaskExample start!");

        HugeGraph graph = ExampleUtil.loadGraph();
        testTask(graph);
        graph.close();

        // Stop daemon thread
        HugeFactory.shutdown(30L);
    }

    public static void testTask(HugeGraph graph) throws InterruptedException {<FILL_FUNCTION_BODY>}

    public static class TestTask extends TaskCallable<Integer> {

        public static final int UNIT = 100; // ms

        public volatile boolean run = true;

        @Override
        public Integer call() throws Exception {
            LOG.info(">>>> running task with parameter: {}", this.task().input());
            for (int i = this.task().progress(); i <= 100 && this.run; i++) {
                LOG.info(">>>> progress {}", i);
                this.task().progress(i);
                this.graph().taskScheduler().save(this.task());
                Thread.sleep(UNIT);
            }
            return 18;
        }
    }
}

        Id id = IdGenerator.of(8);
        String callable = "org.apache.hugegraph.example.TaskExample$TestTask";
        HugeTask<?> task = new HugeTask<>(id, null, callable, "test-parameter");
        task.type("type-1");
        task.name("test-task");

        TaskScheduler scheduler = graph.taskScheduler();
        scheduler.schedule(task);
        scheduler.save(task);
        Iterator<HugeTask<Object>> iter;
        iter = scheduler.tasks(TaskStatus.RUNNING, -1, null);
        LOG.info(">>>> running task: {}", IteratorUtils.toList(iter));

        Thread.sleep(TestTask.UNIT * 33);
        task.cancel(true);
        Thread.sleep(TestTask.UNIT * 1);
        scheduler.save(task);

        // Find task not finished(actually it should be RUNNING)
        iter = scheduler.tasks(TaskStatus.CANCELLED, -1, null);
        assert iter.hasNext();
        task = iter.next();

        LOG.info(">>>> task may be interrupted");

        Thread.sleep(TestTask.UNIT * 10);
        LOG.info(">>>> restore task...");
        Whitebox.setInternalState(task, "status", TaskStatus.RUNNING);
        scheduler.restoreTasks();
        Thread.sleep(TestTask.UNIT * 80);
        scheduler.save(task);

        iter = scheduler.tasks(TaskStatus.SUCCESS, -1, null);
        assert iter.hasNext();
        task = iter.next();
        assert task.status() == TaskStatus.SUCCESS;
        assert task.retries() == 1;
    
<no_super_class>