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:
parent
b9830cba73
commit
be6123b10e
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)},
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue