Skip to content

Add example analysis job endpoint #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions multinet/api/views/network.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
from typing import List, Optional

from django.shortcuts import get_object_or_404
Expand Down Expand Up @@ -219,3 +220,27 @@ def sessions(self, request, parent_lookup_workspace__name: str, name: str):
serializer = NetworkSessionSerializer(sessions, many=True)

return Response(serializer.data, status=status.HTTP_200_OK)

@swagger_auto_schema()
@action(detail=True, methods=['POST'])
@require_workspace_permission(WorkspaceRoleChoice.WRITER)
def algorithm(self, request, parent_lookup_workspace__name: str, name: str):
workspace: Workspace = get_object_or_404(Workspace, name=parent_lookup_workspace__name)
network: Network = get_object_or_404(Network, workspace=workspace, name=name)

print(f'running label propagation on {workspace.name}/{network.name}')
db = workspace.get_arango_db()
job_id = db.pregel.create_job(
graph=network.name,
algorithm='labelpropagation',
store=True,
async_mode=False,
result_field='_community_LP',
)
job = db.pregel.job(job_id)

while job['state'] in {'running', 'storing'}:
time.sleep(0.25)
print('[label propagation] waiting')

return Response(status=status.HTTP_204_NO_CONTENT)