7.1 Task

7.1.1 列出某个图中全部的异步任务

Params
  • status: 异步任务的状态
  • limit:返回异步任务数目上限
Method & Url
  1. GET http://localhost:8080/graphs/hugegraph/tasks?status=success
Response Status
  1. 200
Response Body
  1. {
  2. "tasks": [{
  3. "task_name": "hugegraph.traversal().V()",
  4. "task_progress": 0,
  5. "task_create": 1532943976585,
  6. "task_status": "success",
  7. "task_update": 1532943976736,
  8. "task_result": "0",
  9. "task_retries": 0,
  10. "id": 2,
  11. "task_type": "gremlin",
  12. "task_callable": "com.baidu.hugegraph.api.job.GremlinAPI$GremlinJob",
  13. "task_input": "{\"gremlin\":\"hugegraph.traversal().V()\",\"bindings\":{},\"language\":\"gremlin-groovy\",\"aliases\":{\"hugegraph\":\"graph\"}}"
  14. }]
  15. }

7.1.2 查看某个异步任务的信息

Method & Url
  1. GET http://localhost:8080/graphs/hugegraph/tasks/2
Response Status
  1. 200
Response Body
  1. {
  2. "task_name": "hugegraph.traversal().V()",
  3. "task_progress": 0,
  4. "task_create": 1532943976585,
  5. "task_status": "success",
  6. "task_update": 1532943976736,
  7. "task_result": "0",
  8. "task_retries": 0,
  9. "id": 2,
  10. "task_type": "gremlin",
  11. "task_callable": "com.baidu.hugegraph.api.job.GremlinAPI$GremlinJob",
  12. "task_input": "{\"gremlin\":\"hugegraph.traversal().V()\",\"bindings\":{},\"language\":\"gremlin-groovy\",\"aliases\":{\"hugegraph\":\"graph\"}}"
  13. }

7.1.3 删除某个异步任务信息,不删除异步任务本身

Method & Url
  1. DELETE http://localhost:8080/graphs/hugegraph/tasks/2
Response Status
  1. 204

7.1.4 取消某个异步任务,该异步任务必须具有处理中断的能力

假设已经通过Gremlin API创建了一个异步任务如下:

  1. "for (int i = 0; i < 10; i++) {" +
  2. "hugegraph.addVertex(T.label, 'man');" +
  3. "hugegraph.tx().commit();" +
  4. "try {" +
  5. "sleep(1000);" +
  6. "} catch (InterruptedException e) {" +
  7. "break;" +
  8. "}" +
  9. "}"
Method & Url
  1. PUT http://localhost:8080/graphs/hugegraph/tasks/2?action=cancel

请保证在10秒内发送该请求,如果超过10秒发送,任务可能已经执行完成,无法取消。

Response Status
  1. 202
Response Body
  1. {
  2. "cancelled": true
  3. }

此时查询 label 为 man 的顶点数目,一定是小于 10 的。