本节介绍用于管理进程和作业的方法。
进程
top()
获取数据库中全部正在运行的进程。
参数
config: RequestConfig
(可选):请求配置。
返回值
List[Process]
:获取的进程列表。
# Retrieves all running processes in the database
processes = Conn.top()
for process in processes:
print(process.processId, "-", process.processQuery)
1049542 - MATCH p = ()->{1,3}() RETURN p LIMIT 5000
kill()
终止数据库中正在运行的进程。
参数
id: str
:进程ID;用*
可指定全部正在运行的进程。config: RequestConfig
(可选):请求配置。
返回值
Response
:请求结果。
# Retrieves all running processes in the database and kills them all
processes = Conn.top()
for process in processes:
response = Conn.kill(process.processId)
print(process.processId, "-", process.processQuery, "- Kill", response.status.code.name)
1049607 - MATCH p = ()->{1,3}() RETURN p LIMIT 5000 - Kill SUCCESS
作业
showJob()
获取图的全部作业。
参数
id: str
(可选):作业ID。config: RequestConfig
(可选):请求配置。
返回值
List[Job]
:获取的作业列表。
# Retrieves all failed jobs in the graph 'miniCircle'
requestConfig = RequestConfig(graph="miniCircle")
jobs = Conn.showJob(config=requestConfig)
failed_jobs = [job for job in jobs if job.status == "FAILED"]
if failed_jobs:
for job in failed_jobs:
print(job.id, "-", job.type, "-", job.errMsg)
else:
print("No failed jobs")
51 - Fulltext name already exists. - CREATE_FULLTEXT
42 - Fulltext name already exists. - CREATE_FULLTEXT
26 - [engine] uuids should be unsigned integer - HDC_ALGO
26_1 - - HDC_ALGO
17 - [engine] all failed, because some nodes do not exist in db - HDC_ALGO
17_1 - - HDC_ALGO
stopJob()
停止图中一个正在运行的作业。
参数
id: str
:待停止的作业ID。config: RequestConfig
(可选):请求配置。
返回值
Response
:请求结果。
# Retrieves all running jobs in the graph 'miniCircle' and stops them all
requestConfig = RequestConfig(graph="miniCircle")
jobs = Conn.showJob(config=requestConfig)
running_jobs = [job for job in jobs if job.status == "RUNNING"]
for running_job in running_jobs:
response = Conn.stopJob(running_job.id, requestConfig)
print(running_job.id, "-", running_job.type, "- Stop", response.status.code.name)
10 - CREATE_FULLTEXT - Stop FAILED
10_1- CREATE_FULLTEXT - Stop SUCCESS
10_2 - CREATE_FULLTEXT - Stop SUCCESS
clearJob()
清除图中一个非正在运行的作业。
参数
id: str
:待清除的作业ID。config: RequestConfig
(可选):请求配置。
返回值
Response
:请求结果。
# Retrieves all failed jobs in the graph 'miniCircle' and clears them all
requestConfig = RequestConfig(graph="miniCircle")
jobs = Conn.showJob(config=requestConfig)
failed_jobs = [job for job in jobs if job.status == "FAILED"]
if failed_jobs:
for job in failed_jobs:
response = Conn.clearJob(job.id, requestConfig)
print("Clear", job.id, response.status.code.name)
else:
print("No failed jobs")
Clear 51 SUCCESS
Clear 42 SUCCESS
Clear 26 SUCCESS
Clear 26_1 SUCCESS
Clear 17 SUCCESS
Clear 17_1 SUCCESS
完整示例
from ultipa import UltipaConfig, Connection, RequestConfig
ultipaConfig = UltipaConfig()
# URI example: ultipaConfig.hosts = ["https://mqj4zouys.us-east-1.cloud.ultipa.com:60010"]
ultipaConfig.hosts = ["192.168.1.85:60061", "192.168.1.87:60061", "192.168.1.88:60061"]
ultipaConfig.username = "<username>"
ultipaConfig.password = "<password>"
Conn = Connection.NewConnection(defaultConfig=ultipaConfig)
# Retrieves all failed jobs in the graph 'miniCircle'
requestConfig = RequestConfig(graph="miniCircle")
jobs = Conn.showJob(config=requestConfig)
failed_jobs = [job for job in jobs if job.status == "FAILED"]
if failed_jobs:
for job in failed_jobs:
print(job.id, "-", job.type, "-", job.errMsg)
else:
print("No failed jobs")