Task API Task(任务管理)REST 接口:查询和管理异步任务的执行状态,如索引重建、图遍历等长时任务。
7.1 Task 7.1.1 列出某个图中全部的异步任务 Params status: 异步任务的状态,取值为 NEW、SCHEDULING、SCHEDULED、QUEUED、RESTORING、RUNNING、SUCCESS、CANCELLING、CANCELLED、FAILED、HANGING、DELETING 之一,不区分大小写 ids: 需要查询的任务 id,可以重复传多个。不能与 status 或 page 同时使用,并且会忽略 limit limit:返回异步任务数目上限,默认为 100 page: 分页的页标记,传该参数时响应中会带上下一页的 page 字段 Method & Url
GET http://localhost:8080/graphspaces/DEFAULT/graphs/hugegraph/tasks?status=successResponse Status Response Body
{
"tasks" : [{
"task_name" : "hugegraph.traversal().V()" ,
"task_progress" : 0 ,
"task_create" : 1532943976585 ,
"task_status" : "success" ,
"task_update" : 1532943976736 ,
"task_result" : "0" ,
"task_retries" : 0 ,
"id" : 2 ,
"task_type" : "gremlin" ,
"task_callable" : "org.apache.hugegraph.api.job.GremlinAPI$GremlinJob" ,
"task_input" : "{\"gremlin\":\"hugegraph.traversal().V()\",\"bindings\":{},\"language\":\"gremlin-groovy\",\"aliases\":{\"hugegraph\":\"graph\"}}"
}]
} 7.1.2 查看某个异步任务的信息 Params with_result: 是否加载任务的结果,默认为 true Method & Url
GET http://localhost:8080/graphspaces/DEFAULT/graphs/hugegraph/tasks/2Response Status Response Body
{
"task_name" : "hugegraph.traversal().V()" ,
"task_progress" : 0 ,
"task_create" : 1532943976585 ,
"task_status" : "success" ,
"task_update" : 1532943976736 ,
"task_result" : "0" ,
"task_retries" : 0 ,
"id" : 2 ,
"task_type" : "gremlin" ,
"task_callable" : "org.apache.hugegraph.api.job.GremlinAPI$GremlinJob" ,
"task_input" : "{\"gremlin\":\"hugegraph.traversal().V()\",\"bindings\":{},\"language\":\"gremlin-groovy\",\"aliases\":{\"hugegraph\":\"graph\"}}"
} 7.1.3 删除某个异步任务信息,不删除异步任务本身 Params force: 任务仍在运行时是否强制删除,默认为 false Method & Url
DELETE http://localhost:8080/graphspaces/DEFAULT/graphs/hugegraph/tasks/2Response Status 7.1.4 取消某个异步任务,该异步任务必须具有处理中断的能力 假设已经通过Gremlin API 创建了一个异步任务如下:
"for (int i = 0; i < 10; i++) {" +
"hugegraph.addVertex(T.label, 'man');" +
"hugegraph.tx().commit();" +
"try {" +
"sleep(1000);" +
"} catch (InterruptedException e) {" +
"break;" +
"}" +
"}" Method & Url
PUT http://localhost:8080/graphspaces/DEFAULT/graphs/hugegraph/tasks/2?action=cancel请保证在 10 秒内发送该请求,如果超过 10 秒发送,任务可能已经执行完成,无法取消。
Response Status 对已经完成或者正在取消中的任务发起取消会返回 400。
Response Body 返回整个任务对象,其中 task_status 为 cancelling 或 cancelled:
{
"task_name" : "for (int i = 0; i < 10; i++) {...}" ,
"task_progress" : 0 ,
"task_create" : 1532943976585 ,
"task_status" : "cancelling" ,
"task_update" : 1532943977001 ,
"task_retries" : 0 ,
"id" : 2 ,
"task_type" : "gremlin" ,
"task_callable" : "org.apache.hugegraph.api.job.GremlinAPI$GremlinJob"
} 此时查询 label 为 man 的顶点数目,一定是小于 10 的。
7.2 Algorithm Job 在服务内部以异步任务的方式调度一个 OLAP 算法,返回的 task id 可以用上面的 Task API 跟踪。
Params 路径参数说明:
graphspace: 图空间名称 graph: 图名称 name: 算法名称,已注册的算法有 count_vertex、count_edge、degree_centrality、stress_centrality、betweenness_centrality、closeness_centrality、eigenvector_centrality、triangle_count、cluster_coefficient、lpa、louvain、weak_connected_component、fusiform_similarity、rings、k_core、page_rank 和 subgraph_stat。名称不存在时返回 404。 Method & Url
POST http://localhost:8080/graphspaces/DEFAULT/graphs/hugegraph/jobs/algorithm/page_rankRequest Body 请求体是算法的参数集合,每个算法各自校验自己的参数。传 {} 表示全部使用默认值。
{
"alpha" : 0.15 ,
"times" : 10
} Response Status Response Body 7.3 Computer Job 以异步任务的方式调度一个 HugeGraph-Computer 作业。该作业在服务外部执行,参见 HugeGraph-Computer 。
Params 路径参数说明:
graphspace: 图空间名称 graph: 图名称 name: 算法名称,已注册的有 page_rank、weak_connected_component、lpa、triangle_count 和 louvain。名称不存在时返回 404。 Method & Url
POST http://localhost:8080/graphspaces/DEFAULT/graphs/hugegraph/jobs/computer/page_rankRequest Body 请求体是作业的参数集合,传 {} 表示全部使用默认值。
Response Status Response Body