Skip to content

Commit 3858781

Browse files
committed
Add example analysis job endpoint
1 parent 3c85af2 commit 3858781

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

multinet/api/views/network.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import time
12
from typing import List, Optional
23

34
from django.shortcuts import get_object_or_404
@@ -219,3 +220,25 @@ def sessions(self, request, parent_lookup_workspace__name: str, name: str):
219220
serializer = NetworkSessionSerializer(sessions, many=True)
220221

221222
return Response(serializer.data, status=status.HTTP_200_OK)
223+
224+
@swagger_auto_schema()
225+
@action(detail=True, methods=['POST'])
226+
@require_workspace_permission(WorkspaceRoleChoice.WRITER)
227+
def algorithm(self, request, parent_lookup_workspace__name: str, name: str):
228+
workspace: Workspace = get_object_or_404(Workspace, name=parent_lookup_workspace__name)
229+
network: Network = get_object_or_404(Network, workspace=workspace, name=name)
230+
231+
print(f'running label propagation on {workspace.name}/{network.name}')
232+
db = workspace.get_arango_db()
233+
job_id = db.pregel.create_job(
234+
graph=network.name,
235+
algorithm='labelpropagation',
236+
store=True,
237+
async_mode=False,
238+
result_field='_community_LP',
239+
)
240+
job = db.pregel.job(job_id)
241+
242+
while job['state'] in {'running', 'storing'}:
243+
time.sleep(0.25)
244+
print('[label propagation] waiting')

0 commit comments

Comments
 (0)