diff --git a/backend/oas/provider/openapi.yaml b/backend/oas/provider/openapi.yaml
index 55543ab..d2a0a99 100644
--- a/backend/oas/provider/openapi.yaml
+++ b/backend/oas/provider/openapi.yaml
@@ -231,7 +231,7 @@ paths:
/jobs/unfetched:
get:
summary: Fetch jobs for device
- description: 'Fetches jobs for execution/cancel
Operation is valid only for job with status: submitted or cancelling. After the operation job status is changed to appropriate FETCHED state (QUEUED_FETCHED or CANCELLING_FETCHED)'
+ description: 'Fetches jobs for execution/cancel
Operation is valid only for job with status: submitted or cancelling. After the operation job status is changed to appropriate ready state (submitted or cancelled)'
operationId: getUnfetchedJobs
security: []
tags:
@@ -458,9 +458,9 @@ components:
jobs.InternalFetchableJobStatus:
type: string
enum:
- - queued
+ - submitted
- cancelling
- example: queued
+ example: submitted
jobs.UnfetchedJobsResponse:
type: array
items:
diff --git a/backend/oas/provider/paths/jobs.yaml b/backend/oas/provider/paths/jobs.yaml
index 1bbb563..a51603d 100644
--- a/backend/oas/provider/paths/jobs.yaml
+++ b/backend/oas/provider/paths/jobs.yaml
@@ -136,7 +136,7 @@ jobs.jobId:
jobs.unfetched:
get:
summary: "Fetch jobs for device"
- description: "Fetches jobs for execution/cancel
Operation is valid only for job with status: submitted or cancelling. After the operation job status is changed to appropriate FETCHED state (QUEUED_FETCHED or CANCELLING_FETCHED)"
+ description: "Fetches jobs for execution/cancel
Operation is valid only for job with status: submitted or cancelling. After the operation job status is changed to appropriate ready state (submitted or cancelled)"
operationId: getUnfetchedJobs
security: []
tags:
diff --git a/backend/oas/provider/schemas/jobs.yaml b/backend/oas/provider/schemas/jobs.yaml
index b9db1d9..12be5d6 100644
--- a/backend/oas/provider/schemas/jobs.yaml
+++ b/backend/oas/provider/schemas/jobs.yaml
@@ -112,6 +112,6 @@ jobs.UnfetchedJobsResponse:
jobs.InternalFetchableJobStatus:
type: string
- enum: ["queued", "cancelling"]
- example: "queued"
+ enum: ["submitted", "cancelling"]
+ example: "submitted"
diff --git a/backend/oqtopus_cloud/provider/routers/jobs.py b/backend/oqtopus_cloud/provider/routers/jobs.py
index 4beed36..a3ba89a 100644
--- a/backend/oqtopus_cloud/provider/routers/jobs.py
+++ b/backend/oqtopus_cloud/provider/routers/jobs.py
@@ -4,6 +4,7 @@
from typing import Optional
from fastapi import APIRouter, Depends
+from oqtopus_cloud.common.model_util import model_to_schema_dict
from oqtopus_cloud.common.models.job import Job
from oqtopus_cloud.common.session import get_db
from oqtopus_cloud.provider.conf import logger, tracer
@@ -35,7 +36,7 @@
@router.get(
"/jobs",
- response_model=list[JobId],
+ response_model=list[JobDef],
)
@tracer.capture_method
def get_jobs(
@@ -55,7 +56,7 @@ def get_jobs(
if max_results is not None:
query = query.limit(max_results)
jobs = query.all()
- return jobs
+ return [model_to_schema(job) for job in jobs]
@router.get(
@@ -104,22 +105,18 @@ def get_unfetched_jobs(
@router.get(
- "/jobs/{jobId}",
+ "/jobs/{job_id}",
response_model=JobId,
responses={404: {"model": Detail}, 400: {"model": Detail}, 500: {"model": Detail}},
)
@tracer.capture_method
def get_job(
- jobId: str,
+ job_id: str,
db: Session = Depends(get_db),
) -> JobId | ErrorResponse:
logger.info("invoked get_job")
try:
- id = uuid.UUID(jobId).bytes
- except Exception:
- return BadRequestResponse("Invalid jobId")
- try:
- job = db.get(Job, id)
+ job = db.get(Job, job_id)
if job is None:
return NotFoundErrorResponse("Job not found")
return job.id
@@ -128,25 +125,23 @@ def get_job(
@router.patch(
- "/jobs/{jobId}",
+ "/jobs/{job_id}",
response_model=JobStatusUpdateResponse,
responses={404: {"model": Detail}, 400: {"model": Detail}, 500: {"model": Detail}},
)
@tracer.capture_method
def update_job(
- jobId: str,
+ job_id: str,
request: JobStatusUpdate,
db: Session = Depends(get_db),
) -> JobStatusUpdateResponse | ErrorResponse:
logger.info("invoked get_job")
- try:
- id = uuid.UUID(jobId).bytes
- except Exception:
- return BadRequestResponse("Invalid jobId")
try:
job = (
db.query(Job)
- .filter(Job.id == id, or_(Job.status == "ready", Job.status == "running"))
+ .filter(
+ Job.id == job_id, or_(Job.status == "ready", Job.status == "running")
+ )
.first()
)
if job is None:
@@ -157,3 +152,38 @@ def update_job(
return JobStatusUpdateResponse(message="Job status updated")
except Exception as e:
return InternalServerErrorResponse(f"Error: {str(e)}")
+
+
+MAP_MODEL_TO_SCHEMA = {
+ "id": "id",
+ "owner": "owner",
+ "status": "status",
+ "name": "name",
+ "description": "description",
+ "device_id": "device_id",
+ "job_info": "job_info",
+ "transpiler_info": "transpiler_info",
+ "simulator_info": "simulator_info",
+ "mitigation_info": "mitigation_info",
+ "job_type": "job_type",
+ "shots": "shots",
+ "status": "status",
+ "created_at": "created_at",
+ "updated_at": "updated_at",
+}
+
+
+def model_to_schema(model: Job) -> JobDef:
+ schema_dict = model_to_schema_dict(model, MAP_MODEL_TO_SCHEMA)
+
+ # load as json if not None.
+ # if schema_dict["basis_gates"]:
+ # schema_dict["basis_gates"] = json.loads(schema_dict["basis_gates"])
+ # logger.info("schema_dict!!!:", schema_dict)
+ if schema_dict["created_at"]:
+ schema_dict["created_at"] = schema_dict["created_at"].astimezone(jst)
+ if schema_dict["updated_at"]:
+ schema_dict["updated_at"] = schema_dict["updated_at"].astimezone(jst)
+
+ response = JobDef(**schema_dict)
+ return response
diff --git a/backend/oqtopus_cloud/provider/schemas/__init__.py b/backend/oqtopus_cloud/provider/schemas/__init__.py
index d9ce7c2..0ddc0ae 100644
--- a/backend/oqtopus_cloud/provider/schemas/__init__.py
+++ b/backend/oqtopus_cloud/provider/schemas/__init__.py
@@ -1,4 +1,4 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
-# timestamp: 2024-10-14T08:42:32+00:00
+# timestamp: 2024-10-14T08:52:30+00:00
# version: 0.25.9
diff --git a/backend/oqtopus_cloud/provider/schemas/devices.py b/backend/oqtopus_cloud/provider/schemas/devices.py
index c180538..cb9955e 100644
--- a/backend/oqtopus_cloud/provider/schemas/devices.py
+++ b/backend/oqtopus_cloud/provider/schemas/devices.py
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
-# timestamp: 2024-10-14T08:42:32+00:00
+# timestamp: 2024-10-14T08:52:30+00:00
# version: 0.25.9
from __future__ import annotations
diff --git a/backend/oqtopus_cloud/provider/schemas/error.py b/backend/oqtopus_cloud/provider/schemas/error.py
index adfb731..111aceb 100644
--- a/backend/oqtopus_cloud/provider/schemas/error.py
+++ b/backend/oqtopus_cloud/provider/schemas/error.py
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
-# timestamp: 2024-10-14T08:42:32+00:00
+# timestamp: 2024-10-14T08:52:30+00:00
# version: 0.25.9
from __future__ import annotations
diff --git a/backend/oqtopus_cloud/provider/schemas/jobs.py b/backend/oqtopus_cloud/provider/schemas/jobs.py
index 1a7357b..cf70702 100644
--- a/backend/oqtopus_cloud/provider/schemas/jobs.py
+++ b/backend/oqtopus_cloud/provider/schemas/jobs.py
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
-# timestamp: 2024-10-14T08:42:32+00:00
+# timestamp: 2024-10-14T08:52:30+00:00
# version: 0.25.9
from __future__ import annotations
@@ -93,8 +93,8 @@ class JobStatusUpdateResponse(BaseModel):
message: str
-class InternalFetchableJobStatus(RootModel[Literal["queued", "cancelling"]]):
- root: Annotated[Literal["queued", "cancelling"], Field(examples=["queued"])]
+class InternalFetchableJobStatus(RootModel[Literal["submitted", "cancelling"]]):
+ root: Annotated[Literal["submitted", "cancelling"], Field(examples=["submitted"])]
class UnfetchedJobsResponse(RootModel[list[Union[JobDef, JobId]]]):
diff --git a/backend/oqtopus_cloud/user/routers/jobs.py b/backend/oqtopus_cloud/user/routers/jobs.py
index 5a36809..3b3cbb0 100644
--- a/backend/oqtopus_cloud/user/routers/jobs.py
+++ b/backend/oqtopus_cloud/user/routers/jobs.py
@@ -63,14 +63,7 @@ def get_jobs(
logger.info("invoked!", extra={"owner": owner})
stmt = select(Job).filter(Job.owner == owner).order_by(Job.created_at)
jobs = db.scalars(stmt).all()
- # TODO: get_jobsでの詰替え
- # 外向け(for UI)と内部(for edge)でデータの出し分けをした方がよい
return [model_to_schema(job) for job in jobs]
- # for job in jobs:
- # logger.info(f"job: {job.device_id}")
- # #yield model_to_schema(job)
-
- # return None
except Exception as e:
logger.info(f"error: {str(e)}")
return InternalServerErrorResponse(detail=str(e))
diff --git a/backend/oqtopus_cloud/user/schemas/__init__.py b/backend/oqtopus_cloud/user/schemas/__init__.py
index 8a9138e..ad02e71 100644
--- a/backend/oqtopus_cloud/user/schemas/__init__.py
+++ b/backend/oqtopus_cloud/user/schemas/__init__.py
@@ -1,4 +1,4 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
-# timestamp: 2024-10-14T08:42:24+00:00
+# timestamp: 2024-10-14T08:52:23+00:00
# version: 0.25.9
diff --git a/backend/oqtopus_cloud/user/schemas/devices.py b/backend/oqtopus_cloud/user/schemas/devices.py
index 931dfcb..31f08ad 100644
--- a/backend/oqtopus_cloud/user/schemas/devices.py
+++ b/backend/oqtopus_cloud/user/schemas/devices.py
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
-# timestamp: 2024-10-14T08:42:24+00:00
+# timestamp: 2024-10-14T08:52:23+00:00
# version: 0.25.9
from __future__ import annotations
diff --git a/backend/oqtopus_cloud/user/schemas/error.py b/backend/oqtopus_cloud/user/schemas/error.py
index 3198cd7..5822dec 100644
--- a/backend/oqtopus_cloud/user/schemas/error.py
+++ b/backend/oqtopus_cloud/user/schemas/error.py
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
-# timestamp: 2024-10-14T08:42:24+00:00
+# timestamp: 2024-10-14T08:52:23+00:00
# version: 0.25.9
from __future__ import annotations
diff --git a/backend/oqtopus_cloud/user/schemas/jobs.py b/backend/oqtopus_cloud/user/schemas/jobs.py
index b17fb24..dc13d66 100644
--- a/backend/oqtopus_cloud/user/schemas/jobs.py
+++ b/backend/oqtopus_cloud/user/schemas/jobs.py
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
-# timestamp: 2024-10-14T08:42:24+00:00
+# timestamp: 2024-10-14T08:52:23+00:00
# version: 0.25.9
from __future__ import annotations
diff --git a/backend/oqtopus_cloud/user/schemas/success.py b/backend/oqtopus_cloud/user/schemas/success.py
index 38cf64e..ad70e95 100644
--- a/backend/oqtopus_cloud/user/schemas/success.py
+++ b/backend/oqtopus_cloud/user/schemas/success.py
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
-# timestamp: 2024-10-14T08:42:24+00:00
+# timestamp: 2024-10-14T08:52:23+00:00
# version: 0.25.9
from __future__ import annotations