Skip to content

Commit

Permalink
Merge pull request #640 from stvoutsin/job_delete_optional
Browse files Browse the repository at this point in the history
Make TAP job deletion optional defaulting to True
  • Loading branch information
bsipocz authored Jan 16, 2025
2 parents a0ab0e9 + f765128 commit 323fae4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Enhancements and Fixes
----------------------

- Make deletion of TAP jobs optional via a new ``delete`` kwarg. [#640]

Deprecations and Removals
-------------------------
Expand Down
28 changes: 20 additions & 8 deletions pyvo/dal/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def run_sync(

def run_async(
self, query, *, language="ADQL", maxrec=None, uploads=None,
**keywords):
delete=True, **keywords):
"""
runs async query and returns its result
Expand All @@ -297,6 +297,8 @@ def run_async(
the maximum records to return. defaults to the service default
uploads : dict
a mapping from table names to objects containing a votable
delete : bool
delete the job after fetching the results
Returns
-------
Expand All @@ -323,7 +325,9 @@ def run_async(
job = job.run().wait()
job.raise_if_error()
result = job.fetch_result()
job.delete()

if delete:
job.delete()

return result

Expand Down Expand Up @@ -643,17 +647,22 @@ def create(
job = cls(response.url, session=session)
return job

def __init__(self, url, *, session=None):
def __init__(self, url, *, session=None, delete=True):
"""
initialize the job object with the given url and fetch remote values
Parameters
----------
url : str
the job url
session : object, optional
session to use for network requests
delete : bool, optional
whether to delete the job when exiting (default: True)
"""
self._url = url
self._session = use_session(session)
self._delete_on_exit = delete
self._update()

def __enter__(self):
Expand All @@ -664,12 +673,15 @@ def __enter__(self):

def __exit__(self, exc_type, exc_val, exc_tb):
"""
Exits the context. The job is silently deleted.
Exits the context. Unless delete=False was set at initialization,
the job is deleted. Any deletion errors are silently ignored
to ensure proper context exit.
"""
try:
self.delete()
except Exception:
pass
if self._delete_on_exit:
try:
self.delete()
except DALServiceError:
pass

def _update(self, wait_for_statechange=False, timeout=10.):
"""
Expand Down

0 comments on commit 323fae4

Please sign in to comment.