Skip to content

Commit

Permalink
webserver
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg committed Mar 19, 2023
1 parent a91f8a6 commit 3ea4c7f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,15 @@ def set_client(app: web.Application, obj: ComputationsApi):

@log_decorator(logger=log)
async def create_or_update_pipeline(
app: web.Application, user_id: UserID, project_id: ProjectID
app: web.Application, user_id: UserID, project_id: ProjectID, product_name: str
) -> Optional[DataType]:
settings: DirectorV2Settings = get_plugin_settings(app)

backend_url = settings.base_url / "computations"
body = {
"user_id": user_id,
"project_id": f"{project_id}",
"product_name": product_name,
}
# request to director-v2
try:
Expand All @@ -122,7 +123,6 @@ async def create_or_update_pipeline(
async def is_pipeline_running(
app: web.Application, user_id: PositiveInt, project_id: UUID
) -> Optional[bool]:

# TODO: make it cheaper by /computations/{project_id}/state. First trial shows
# that the efficiency gain is minimal but should be considered specially if the handler
# gets heavier with time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ async def add_new_project(
if _project_db["uuid"] != str(project.uuid):
raise ExporterException("Project uuid dose nto match after validation")

await create_or_update_pipeline(app, user_id, project.uuid)
await create_or_update_pipeline(app, user_id, project.uuid, product_name)


async def _fix_node_run_hashes_based_on_old_project(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

from .. import catalog_client, director_v2_api, storage_api
from ..application_settings import get_settings
from ..products import get_product_name
from ..resource_manager.websocket_manager import (
PROJECT_ID_KEY,
UserSessionID,
Expand Down Expand Up @@ -276,7 +277,7 @@ async def add_project_node(
# also ensure the project is updated by director-v2 since services
# are due to access comp_tasks at some point see [https://github.com/ITISFoundation/osparc-simcore/issues/3216]
await director_v2_api.create_or_update_pipeline(
request.app, user_id, project["uuid"]
request.app, user_id, project["uuid"], product_name
)

if _is_node_dynamic(service_key):
Expand Down Expand Up @@ -352,7 +353,10 @@ async def delete_project_node(
partial_workbench_data, user_id, f"{project_uuid}"
)
# also ensure the project is updated by director-v2 since services
await director_v2_api.create_or_update_pipeline(request.app, user_id, project_uuid)
product_name = get_product_name(request)
await director_v2_api.create_or_update_pipeline(
request.app, user_id, project_uuid, product_name
)


async def update_project_linked_product(
Expand Down Expand Up @@ -591,7 +595,6 @@ async def try_open_project_for_user(
await get_user_name(app, user_id),
notify_users=False,
):

with managed_resource(user_id, client_session_id, app) as rt:
# NOTE: if max_number_of_studies_per_user is set, the same
# project shall still be openable if the tab was closed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ async def create_projects(request: web.Request):
request_context=req_ctx,
query_params=query_params,
predefined_project=predefined_project,
product_name=req_ctx.product_name,
fire_and_forget=True,
)

Expand Down Expand Up @@ -249,7 +250,8 @@ async def _create_projects(
query_params: _ProjectCreateParams,
request_context: RequestContext,
predefined_project: Optional[ProjectDict],
):
product_name: str,
) -> None:
"""
:raises web.HTTPBadRequest
Expand Down Expand Up @@ -313,7 +315,7 @@ async def _create_projects(

# This is a new project and every new graph needs to be reflected in the pipeline tables
await director_v2_api.create_or_update_pipeline(
app, request_context.user_id, new_project["uuid"]
app, request_context.user_id, new_project["uuid"], product_name
)

# Appends state
Expand Down Expand Up @@ -636,7 +638,10 @@ async def replace_project(request: web.Request):
request.app, path_params.project_id
)
await director_v2_api.create_or_update_pipeline(
request.app, req_ctx.user_id, path_params.project_id
request.app,
req_ctx.user_id,
path_params.project_id,
product_name=req_ctx.product_name,
)
# Appends state
new_project = await projects_api.add_project_states_for_user(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,4 @@ async def add_new_project(
#
# TODO: Ensure this user has access to these services!
#
await create_or_update_pipeline(app, user.id, project.uuid)
await create_or_update_pipeline(app, user.id, project.uuid, product_name)
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ def cluster_id(faker: Faker) -> ClusterID:


async def test_create_pipeline(
mocked_director_v2, client, user_id: UserID, project_id: ProjectID
mocked_director_v2,
client,
user_id: UserID,
project_id: ProjectID,
osparc_product_name: str,
):
task_out = await director_v2_api.create_or_update_pipeline(
client.app, user_id, project_id
client.app, user_id, project_id, osparc_product_name
)
assert task_out
assert isinstance(task_out, dict)
Expand Down

0 comments on commit 3ea4c7f

Please sign in to comment.