use of com.baidu.hugegraph.entity.query.ExecuteHistory in project incubator-hugegraph-toolchain by apache.
the class ExecuteHistoryService method remove.
@Transactional(isolation = Isolation.READ_COMMITTED)
public void remove(int connId, int id) {
ExecuteHistory history = this.mapper.selectById(id);
HugeClient client = this.getClient(connId);
if (history.getType().equals(ExecuteType.GREMLIN_ASYNC)) {
client.task().delete(history.getAsyncId());
}
if (this.mapper.deleteById(id) != 1) {
throw new InternalException("entity.delete.failed", history);
}
}
use of com.baidu.hugegraph.entity.query.ExecuteHistory in project incubator-hugegraph-toolchain by apache.
the class ExecuteHistoryService method get.
public ExecuteHistory get(int connId, int id) {
HugeClient client = this.getClient(connId);
ExecuteHistory history = this.mapper.selectById(id);
if (history.getType().equals(ExecuteType.GREMLIN_ASYNC)) {
try {
Task task = client.task().get(history.getAsyncId());
history.setDuration(task.updateTime() - task.createTime());
history.setAsyncStatus(task.status().toUpperCase());
} catch (Exception e) {
history.setDuration(0L);
history.setAsyncStatus(AsyncTaskStatus.UNKNOWN);
}
}
return history;
}
use of com.baidu.hugegraph.entity.query.ExecuteHistory in project incubator-hugegraph-toolchain by apache.
the class GremlinQueryController method executeAsyncTask.
@PostMapping("async-task")
public ExecuteStatus executeAsyncTask(@PathVariable("connId") int connId, @RequestBody GremlinQuery query) {
this.checkParamsValid(query);
Date createTime = HubbleUtil.nowDate();
// Insert execute history
ExecuteStatus status = ExecuteStatus.ASYNC_TASK_RUNNING;
ExecuteHistory history;
history = new ExecuteHistory(null, connId, 0L, ExecuteType.GREMLIN_ASYNC, query.getContent(), status, AsyncTaskStatus.UNKNOWN, -1L, createTime);
this.historyService.save(history);
StopWatch timer = StopWatch.createStarted();
long asyncId = 0L;
try {
asyncId = this.queryService.executeAsyncTask(connId, query);
status = ExecuteStatus.ASYNC_TASK_SUCCESS;
return status;
} catch (Throwable e) {
status = ExecuteStatus.ASYNC_TASK_FAILED;
throw e;
} finally {
timer.stop();
long duration = timer.getTime(TimeUnit.MILLISECONDS);
history.setStatus(status);
history.setDuration(duration);
history.setAsyncId(asyncId);
this.historyService.update(history);
}
}
use of com.baidu.hugegraph.entity.query.ExecuteHistory in project incubator-hugegraph-toolchain by apache.
the class ExecuteHistoryController method delete.
@DeleteMapping("{id}")
public ExecuteHistory delete(@PathVariable("connId") int connId, @PathVariable("id") int id) {
ExecuteHistory oldEntity = this.service.get(connId, id);
if (oldEntity == null) {
throw new ExternalException("execute-history.not-exist.id", id);
}
this.service.remove(connId, id);
return oldEntity;
}
use of com.baidu.hugegraph.entity.query.ExecuteHistory in project incubator-hugegraph-toolchain by apache.
the class ExecuteHistoryService method list.
public IPage<ExecuteHistory> list(int connId, long current, long pageSize) {
HugeClient client = this.getClient(connId);
QueryWrapper<ExecuteHistory> query = Wrappers.query();
query.eq("conn_id", connId).orderByDesc("create_time");
Page<ExecuteHistory> page = new Page<>(current, pageSize);
IPage<ExecuteHistory> results = this.mapper.selectPage(page, query);
int limit = this.config.get(HubbleOptions.EXECUTE_HISTORY_SHOW_LIMIT);
if (results.getTotal() > limit) {
log.debug("Execute history total records: {}", results.getTotal());
results.setTotal(limit);
}
// Get the status of successful execution of asynchronous tasks
Instant now = HubbleUtil.nowTime();
results.getRecords().forEach((p) -> {
if (p.getType().equals(ExecuteType.GREMLIN_ASYNC)) {
try {
Task task = client.task().get(p.getAsyncId());
long endDate = task.updateTime() > 0 ? task.updateTime() : now.getLong(ChronoField.INSTANT_SECONDS);
p.setDuration(endDate - task.createTime());
p.setAsyncStatus(task.status().toUpperCase());
} catch (Exception e) {
p.setDuration(0L);
p.setAsyncStatus(AsyncTaskStatus.UNKNOWN);
}
}
});
return results;
}
Aggregations