本节介绍用于管理进程和作业的方法。
进程
top()
获取数据库中全部正在运行的进程。
参数
config?: RequestConfig
:请求配置。
返回值
Process[]
:获取的进程列表。
// Retrieves all running processes in the database
const processes = await driver.top();
for (const process of processes){
console.log(`${process.processId} - ${process.processQuery}`);
}
1049542 - MATCH p = ()->{1,3}() RETURN p LIMIT 5000
kill()
终止数据库中正在运行的进程。
参数
processId: string
:进程ID。config?: RequestConfig
:请求配置。
返回值
Response
:请求结果。
// Retrieves all running processes in the database and kills them all
const processes = await driver.top();
for (const process of processes) {
console.log("Attempting to kill process", process.processId);
const response = await driver.kill(process.processId);
}
Attempting to kill process 1049141
Attempting to kill process 1049140
作业
showJob()
获取图的全部作业。
参数
id?: string
:作业ID。config?: RequestConfig
:请求配置。
返回值
Job[]
:获取的作业列表。
// Retrieves all jobs in the graph 'miniCircle'
const requestConfig: RequestConfig = { graph: "miniCircle" };
const jobs = await driver.showJob(undefined, requestConfig);
if (jobs.length > 0) {
for (const job of jobs) {
console.log(`${job.id} - ${job.type} - ${job.status}`);
}
} else {
console.log("No jobs found");
}
22 - CREATE_FULLTEXT - FINISHED
22_1 - CREATE_FULLTEXT - FINISHED
21 - CREATE_FULLTEXT - FAILED
20 - CREATE_FULLTEXT - FINISHED
20_1 - CREATE_FULLTEXT - FINISHED
stopJob()
停止图中一个正在运行的作业。
参数
id: string
:待停止的作业ID。config?: RequestConfig
:请求配置。
返回值
Response
:请求结果。
// Retrieves all running jobs in the graph 'miniCircle' and stops them all
const requestConfig: RequestConfig = { graph: "miniCircle" };
const jobs = await driver.showJob(undefined, requestConfig);
const running_jobs = jobs.filter((job) => job.status === "RUNNING");
if (running_jobs.length > 0) {
for (const running_job of running_jobs) {
const response = await driver.stopJob(running_job.id, requestConfig);
console.log(
`Attempting to stop job ${running_job.id} - ${running_job.type}`
);
}
} else {
console.log("No running jobs found");
}
Attempting to stop job 10 - CREATE_HDC_GRAPH
clearJob()
清除图中一个非正在运行的作业。
参数
id: string
:待清除的作业ID。config?: RequestConfig
:请求配置。
返回值
Response
:请求结果。
// Retrieves all failed jobs in the graph 'miniCircle' and clears them all
const requestConfig: RequestConfig = { graph: "miniCircle" };
const jobs = await driver.showJob(undefined,requestConfig);
const failed_jobs = jobs.filter((job) => job.status === "FAILED");
if (failed_jobs.length > 0) {
for (const job of failed_jobs) {
const response = await driver.clearJob(job.id, requestConfig);
console.log(`Clear job ${job.id} ${response.status?.message}`);
}
} else {
console.log("No failed jobs found");
}
Clear job 51 SUCCESS
Clear job 42 SUCCESS
Clear job 26 SUCCESS
Clear job 26_1 SUCCESS
完整示例
import { UltipaDriver } from "@ultipa-graph/ultipa-driver";
import { ULTIPA } from "@ultipa-graph/ultipa-driver/dist/types/index.js";
import { RequestConfig } from "@ultipa-graph/ultipa-driver/dist/types/types.js";
let sdkUsage = async () => {
const ultipaConfig: ULTIPA.UltipaConfig = {
// URI example: hosts: ["xxxx.us-east-1.cloud.ultipa.com:60010"]
hosts: ["10.xx.xx.xx:60010"],
username: "<username>",
password: "<password>"
};
const driver = new UltipaDriver(ultipaConfig);
// Retrieves all jobs in the graph 'miniCircle'
const requestConfig: RequestConfig = { graph: "miniCircle" };
const jobs = await driver.showJob(undefined, requestConfig);
if (jobs.length > 0) {
for (const job of jobs) {
console.log(`${job.id} - ${job.type} - ${job.status}`);
}
} else {
console.log("No jobs found");
}
};
sdkUsage().catch(console.error);