-
Notifications
You must be signed in to change notification settings - Fork 191
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 error details for failed remote job #370
Changes from all commits
71e9d2b
e1ec6b0
8a87a98
c83bb86
535d2ed
5339d06
71bee78
076d7b7
bb926f6
f33a17c
899229e
4c81ff2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,13 +73,15 @@ class Job: | |
status (strawberryfields.api.JobStatus): the job status | ||
connection (strawberryfields.api.Connection): the connection over which the | ||
job is managed | ||
meta (dict[str, str]): metadata related to job execution | ||
""" | ||
|
||
def __init__(self, id_: str, status: JobStatus, connection): | ||
def __init__(self, id_: str, status: JobStatus, connection, meta: dict = None): | ||
self._id = id_ | ||
self._status = status | ||
self._connection = connection | ||
self._result = None | ||
self._meta = meta or {} | ||
|
||
self.log = create_logger(__name__) | ||
|
||
|
@@ -119,14 +121,27 @@ def result(self) -> Result: | |
) | ||
return self._result | ||
|
||
@property | ||
def meta(self) -> dict: | ||
"""Returns a dictionary of metadata on job execution, such as error | ||
details. | ||
|
||
Returns: | ||
dict[str, str] | ||
""" | ||
return self._meta | ||
|
||
def refresh(self): | ||
"""Refreshes the status of an open or queued job, | ||
"""Refreshes the status and metadata of an open or queued job, | ||
along with the job result if the job is newly completed. | ||
""" | ||
if self._status.is_final: | ||
self.log.warning("A %s job cannot be refreshed", self._status.value) | ||
return | ||
self._status = JobStatus(self._connection.get_job_status(self.id)) | ||
job_info = self._connection.get_job(self.id) | ||
self._status = JobStatus(job_info.status) | ||
self._meta = job_info.meta | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be a good idea to log the retrieved metadata at the DEBUG level here? Combined with #360, this will allow retrieved job metadata to appear within the users logs (if they decide to configure it). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, this has been added! Let me know if you think the message formatting needs to be changed. |
||
self.log.debug("Job %s metadata: %s", self.id, job_info.meta) | ||
if self._status == JobStatus.COMPLETED: | ||
self._result = self._connection.get_job_result(self.id) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -547,8 +547,8 @@ def run(self, program: Program, *, compile_options=None, **kwargs) -> Optional[R | |
|
||
if job.status == "failed": | ||
message = ( | ||
"The remote job %s failed due to an internal " | ||
"server error. Please try again." % job.id | ||
"The remote job {} failed due to an internal " | ||
"server error. Please try again. {}".format(job.id, job.meta) | ||
Comment on lines
+550
to
+551
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These were previously made so such that they can be used for logging, but here the message is already pre-defined, so I guess |
||
) | ||
self.log.error(message) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logically for me, the
meta
data belongs to the status of theJob
. At least this attribute will change the similarly to the change instatus
and as far as I understand it, is meant to provide more details about the status of theJob
.However, making this change in abstraction might not be so easy (would involve restructuring
JobStatus
, etc.), so I'm happy as is now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree with the general idea, and also that it would be a relatively big change, so it seems best to tackle that in the future 🙂