Skip to content
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

Add callbacks for download and job complete #132

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions cdmtaskservice/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
app.include_router(routes.ROUTER_GENERAL)
app.include_router(routes.ROUTER_JOBS)
app.include_router(routes.ROUTER_ADMIN)
app.include_router(routes.ROUTER_CALLBACKS)

Check warning on line 71 in cdmtaskservice/app.py

View check run for this annotation

Codecov / codecov/patch

cdmtaskservice/app.py#L71

Added line #L71 was not covered by tests

async def build_app_wrapper():
await app_state.build_app(app, cfg)
Expand Down
17 changes: 16 additions & 1 deletion cdmtaskservice/callback_url_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

_CALLBACK = "callback"
_DOWNLOAD_COMPLETE = "download"
_JOB_COMPLETE = "job"


def get_download_complete_callback(root_url: str = None, job_id: str = None):
Expand All @@ -14,7 +15,21 @@ def get_download_complete_callback(root_url: str = None, job_id: str = None):
root_url - prepend the path with the given root url.
job_id - suffix the path with a job ID.
"""
return _get_callback(_DOWNLOAD_COMPLETE, root_url, job_id)


def get_job_complete_callback(root_url: str = None, job_id: str = None):
"""
Get a url or path for a service callback to communicate that a remote job is complete.

root_url - prepend the path with the given root url.
job_id - suffix the path with a job ID.
"""
return _get_callback(_JOB_COMPLETE, root_url, job_id)


def _get_callback(subpath: str, root_url: str = None, job_id: str = None):
cb = [root_url] if root_url else []
cb += [_CALLBACK, _DOWNLOAD_COMPLETE]
cb += [_CALLBACK, subpath]
cb += [job_id] if job_id else []
return "/".join(cb)
39 changes: 38 additions & 1 deletion cdmtaskservice/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import datetime
import logging
from fastapi import (
APIRouter,
Depends,
Expand All @@ -12,9 +13,14 @@
)
from pydantic import BaseModel, Field
from typing import Annotated

from cdmtaskservice import app_state
from cdmtaskservice import kb_auth
from cdmtaskservice import models
from cdmtaskservice.callback_url_paths import (
get_download_complete_callback,
get_job_complete_callback,
)
from cdmtaskservice.exceptions import UnauthorizedError
from cdmtaskservice.git_commit import GIT_COMMIT
from cdmtaskservice.http_bearer import KBaseHTTPBearer
Expand All @@ -25,8 +31,9 @@

# may need to split these into different files if this file gets too big
ROUTER_GENERAL = APIRouter(tags=["General"])
ROUTER_ADMIN = APIRouter(tags=["Admin"], prefix="/admin")
ROUTER_JOBS = APIRouter(tags=["Jobs"], prefix="/jobs")
ROUTER_ADMIN = APIRouter(tags=["Admin"], prefix="/admin")
ROUTER_CALLBACKS = APIRouter(tags=["Callbacks"])

_AUTH = KBaseHTTPBearer()

Expand Down Expand Up @@ -223,5 +230,35 @@
)


@ROUTER_CALLBACKS.get(
f"/{get_download_complete_callback()}/{{job_id}}",
summary="Report data download complete",
description="Report that data download for a job is complete. This method is not expected "
+ "to be called by users."
)
async def download_complete(
r: Request,
job_id: _ANN_JOB_ID
):
logging.getLogger(__name__).info(f"Download reported as complete for job {job_id}")

Check warning on line 243 in cdmtaskservice/routes.py

View check run for this annotation

Codecov / codecov/patch

cdmtaskservice/routes.py#L243

Added line #L243 was not covered by tests
# TODO NOW implement
raise NotImplementedError()

Check warning on line 245 in cdmtaskservice/routes.py

View check run for this annotation

Codecov / codecov/patch

cdmtaskservice/routes.py#L245

Added line #L245 was not covered by tests


@ROUTER_CALLBACKS.get(
f"/{get_job_complete_callback()}/{{job_id}}",
summary="Report job complete",
description="Report a remote job is complete. This method is not expected "
+ "to be called by users."
)
async def job_complete(
r: Request,
job_id: _ANN_JOB_ID
):
logging.getLogger(__name__).info(f"Remote job reported as complete for job {job_id}")

Check warning on line 258 in cdmtaskservice/routes.py

View check run for this annotation

Codecov / codecov/patch

cdmtaskservice/routes.py#L258

Added line #L258 was not covered by tests
# TODO JOBS implement when job is complete
raise NotImplementedError()

Check warning on line 260 in cdmtaskservice/routes.py

View check run for this annotation

Codecov / codecov/patch

cdmtaskservice/routes.py#L260

Added line #L260 was not covered by tests


class ClientLifeTimeError(Exception):
""" An error thrown when a client's lifetime is less than required. """
Loading