1
1
__all__ = ["Pregel" ]
2
2
3
- from typing import Optional
3
+ from typing import Optional , Sequence
4
4
5
5
from arango .api import ApiGroup
6
6
from arango .exceptions import (
7
7
PregelJobCreateError ,
8
8
PregelJobDeleteError ,
9
9
PregelJobGetError ,
10
10
)
11
- from arango .formatter import format_pregel_job_data
11
+ from arango .formatter import format_pregel_job_data , format_pregel_job_list
12
12
from arango .request import Request
13
13
from arango .response import Response
14
14
from arango .result import Result
@@ -49,6 +49,8 @@ def create_job(
49
49
async_mode : Optional [bool ] = None ,
50
50
result_field : Optional [str ] = None ,
51
51
algorithm_params : Optional [Json ] = None ,
52
+ vertexCollections : Optional [Sequence [str ]] = None ,
53
+ edgeCollections : Optional [Sequence [str ]] = None ,
52
54
) -> Result [int ]:
53
55
"""Start a new Pregel job.
54
56
@@ -74,12 +76,21 @@ def create_job(
74
76
:type result_field: str | None
75
77
:param algorithm_params: Additional algorithm parameters.
76
78
:type algorithm_params: dict | None
79
+ :param vertexCollections: List of vertex collection names.
80
+ :type vertexCollections: Sequence[str] | None
81
+ :param edgeCollections: List of edge collection names.
82
+ :type edgeCollections: Sequence[str] | None
77
83
:return: Pregel job ID.
78
84
:rtype: int
79
85
:raise arango.exceptions.PregelJobCreateError: If create fails.
80
86
"""
81
87
data : Json = {"algorithm" : algorithm , "graphName" : graph }
82
88
89
+ if vertexCollections is not None :
90
+ data ["vertexCollections" ] = vertexCollections
91
+ if edgeCollections is not None :
92
+ data ["edgeCollections" ] = edgeCollections
93
+
83
94
if algorithm_params is None :
84
95
algorithm_params = {}
85
96
@@ -122,3 +133,20 @@ def response_handler(resp: Response) -> bool:
122
133
raise PregelJobDeleteError (resp , request )
123
134
124
135
return self ._execute (request , response_handler )
136
+
137
+ def jobs (self ) -> Result [Json ]:
138
+ """Returns a list of currently running and recently
139
+ finished Pregel jobs without retrieving their results.
140
+
141
+ :return: Details of each running or recently finished Pregel job.
142
+ :rtype: dict
143
+ :raise arango.exceptions.PregelJobGetError: If retrieval fails.
144
+ """
145
+ request = Request (method = "get" , endpoint = "/_api/control_pregel" )
146
+
147
+ def response_handler (resp : Response ) -> Json :
148
+ if resp .is_success :
149
+ return format_pregel_job_list (resp .body )
150
+ raise PregelJobGetError (resp , request )
151
+
152
+ return self ._execute (request , response_handler )
0 commit comments