Skip to content

Commit

Permalink
Rename function.get_jobs to function.jobs and make it return Job obje…
Browse files Browse the repository at this point in the history
…cts (#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
  • Loading branch information
akihikokuroda authored Sep 11, 2024
1 parent b9830cb commit be6123b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
3 changes: 2 additions & 1 deletion client/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions client/qiskit_serverless/core/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def run(self, **kwargs):
config=config,
)

def get_jobs(self):
def jobs(self):
"""Run function
Raises:
Expand All @@ -127,6 +127,10 @@ def get_jobs(self):
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.")

Expand All @@ -138,10 +142,15 @@ def get_jobs(self):
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.
Expand Down
4 changes: 4 additions & 0 deletions gateway/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def get_serializer_run_program(*args, **kwargs):
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)},
Expand Down
18 changes: 11 additions & 7 deletions gateway/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from .serializers import (
JobConfigSerializer,
RunJobSerializer,
JobSerializer,
RunProgramSerializer,
UploadProgramSerializer,
RetrieveCatalogSerializer,
Expand Down Expand Up @@ -105,6 +106,14 @@ def get_serializer_run_job(*args, **kwargs):

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

Expand Down Expand Up @@ -412,13 +421,8 @@ def get_jobs(
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):
Expand Down
2 changes: 1 addition & 1 deletion tests/basic/06_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
print(job.result())
print(job.logs())

jobs = my_function.get_jobs()
jobs = my_function.jobs()
print(jobs)

0 comments on commit be6123b

Please sign in to comment.