Rename function.get_jobs to function.jobs and make it return Job objects (#1480)

* rename get_jobs to jobs and return Job objects

* lint

* fix tests

* lint

* lint

* lint

* lint

* disable cyclic-import lint check

* restore image version

* restore compose file

* review comments

* review comments

* review comments

* review comments

* review comments
This commit is contained in:
Akihiko (Aki) Kuroda 2024-09-11 11:09:10 -04:00 committed by GitHub
parent b9830cba73
commit be6123b10e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 29 additions and 11 deletions

View File

@ -81,7 +81,8 @@ disable=raw-checker-failed,
suppressed-message,
useless-suppression,
deprecated-pragma,
use-symbolic-message-instead
use-symbolic-message-instead,
cyclic-import
# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option

View File

@ -118,7 +118,7 @@ class QiskitFunction: # pylint: disable=too-many-instance-attributes
config=config,
)
def get_jobs(self):
def jobs(self):
"""Run function
Raises:
@ -127,6 +127,10 @@ class QiskitFunction: # pylint: disable=too-many-instance-attributes
Returns:
Job ids : job executed this function
"""
from qiskit_serverless.core.job import ( # pylint: disable=import-outside-toplevel
Job,
)
if self.job_client is None:
raise ValueError("No clients specified for a function.")
@ -138,10 +142,15 @@ class QiskitFunction: # pylint: disable=too-many-instance-attributes
f"Function validation failed. Validation errors:\n {error_string}",
)
return self.job_client.get_jobs(
response = self.job_client.get_jobs(
title=self.title,
provider=self.provider,
)
jobs = [
Job(job_id=job.get("id"), job_client=self.job_client, raw_data=job)
for job in response
]
return jobs
def _validate_function(self) -> Tuple[bool, List[str]]:
"""Validate function arguments using schema provided.

View File

@ -38,6 +38,10 @@ class ProgramViewSet(views.ProgramViewSet):
def get_serializer_run_job(*args, **kwargs):
return v1_serializers.RunJobSerializer(*args, **kwargs)
@staticmethod
def get_serializer_job(*args, **kwargs):
return v1_serializers.JobSerializer(*args, **kwargs)
@swagger_auto_schema(
operation_description="List author Qiskit Functions",
responses={status.HTTP_200_OK: v1_serializers.ProgramSerializer(many=True)},

View File

@ -45,6 +45,7 @@ from .ray import get_job_handler
from .serializers import (
JobConfigSerializer,
RunJobSerializer,
JobSerializer,
RunProgramSerializer,
UploadProgramSerializer,
RetrieveCatalogSerializer,
@ -105,6 +106,14 @@ class ProgramViewSet(viewsets.GenericViewSet):
return RunJobSerializer(*args, **kwargs)
@staticmethod
def get_serializer_job(*args, **kwargs):
"""
This method returns the job serializer
"""
return JobSerializer(*args, **kwargs)
def get_serializer_class(self):
return self.serializer_class
@ -412,13 +421,8 @@ class ProgramViewSet(viewsets.GenericViewSet):
jobs = Job.objects.filter(program=program)
else:
jobs = Job.objects.filter(program=program, author=request.user)
return Response(
list(
jobs.values(
"status", "result", "id", "created", "version", "arguments"
)
)
)
serializer = self.get_serializer_job(jobs, many=True)
return Response(serializer.data)
class JobViewSet(viewsets.GenericViewSet):

View File

@ -35,5 +35,5 @@ job = my_function.run(message="Argument for the custum function")
print(job.result())
print(job.logs())
jobs = my_function.get_jobs()
jobs = my_function.jobs()
print(jobs)