Skip to content
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

feat: add job_timeout_ms to job configuration classes #1675

Merged
merged 23 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ada7d68
fix: adds new property and tests
chalmerlowe Oct 5, 2023
496472b
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Oct 5, 2023
0cd9653
updates docs to correct a sphinx failure
chalmerlowe Oct 5, 2023
28a1fa9
Updates formatting
chalmerlowe Oct 5, 2023
5fbb7d6
Update tests/system/test_query.py
chalmerlowe Oct 5, 2023
36a2c1f
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Oct 5, 2023
ee9ffc5
Merge branch 'main' into fix/add-job_timeout_ms
chalmerlowe Oct 9, 2023
968db9a
Update google/cloud/bigquery/job/base.py
chalmerlowe Oct 11, 2023
a3b84b4
updates one test and uses int_or_none
chalmerlowe Oct 12, 2023
b619e5b
Update tests/system/test_query.py
chalmerlowe Oct 24, 2023
be2e945
Update tests/system/test_query.py
chalmerlowe Oct 24, 2023
91edae4
testing coverage feature
chalmerlowe Oct 24, 2023
e2a05a9
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Oct 24, 2023
d694d71
minor edits
chalmerlowe Oct 25, 2023
037417a
tweaks to noxfile for testing purposes
chalmerlowe Oct 25, 2023
4bbb4df
add new test to base as experiment
chalmerlowe Oct 25, 2023
0d9ae32
adds a test, updates import statements
chalmerlowe Nov 13, 2023
dc585d5
add another test
chalmerlowe Nov 13, 2023
aa4d302
edit to tests
chalmerlowe Nov 13, 2023
6e72fd4
formatting fixes
chalmerlowe Nov 13, 2023
69365f5
update noxfile to correct debug code
chalmerlowe Nov 14, 2023
ec05fbf
Merge branch 'main' into fix/add-job_timeout_ms
chalmerlowe Nov 14, 2023
edaaf19
removes unneeded comments.
chalmerlowe Nov 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions google/cloud/bigquery/job/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from google.cloud.bigquery import _helpers
from google.cloud.bigquery.retry import DEFAULT_RETRY
from google.cloud.bigquery._helpers import _int_or_none

if typing.TYPE_CHECKING: # pragma: NO COVER
from google.api_core import retry as retries
Expand Down Expand Up @@ -171,6 +172,37 @@ def __setattr__(self, name, value):
)
super(_JobConfig, self).__setattr__(name, value)

@property
def job_timeout_ms(self):
"""Optional parameter. Job timeout in milliseconds. If this time limit is exceeded, BigQuery might attempt to stop the job.
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfiguration.FIELDS.job_timeout_ms
e.g.

job_config = bigquery.QueryJobConfig( job_timeout_ms = 5000 )
or
job_config.job_timeout_ms = 5000

Raises:
ValueError: If ``value`` type is invalid.
"""

# None as this is an optional parameter.
if self._properties.get("jobTimeoutMs"):
chalmerlowe marked this conversation as resolved.
Show resolved Hide resolved
return self._properties["jobTimeoutMs"]
return None

@job_timeout_ms.setter
def job_timeout_ms(self, value):
try:
value = _int_or_none(value)
except ValueError as err:
raise ValueError("Pass an int for jobTimeoutMs, e.g. 5000").with_traceback(
err.__traceback__
)

""" Docs indicate a string is expected by the API """
self._properties["jobTimeoutMs"] = str(value)

@property
def labels(self):
"""Dict[str, str]: Labels for the job.
Expand Down
7 changes: 6 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,12 @@ def system(session):
session.install("-e", f".{extras}", "-c", constraints_path)

# Run py.test against the system tests.
session.run("py.test", "--quiet", os.path.join("tests", "system"), *session.posargs)
session.run(
"py.test",
"--quiet",
os.path.join("tests", "system"),
*session.posargs,
)


@nox.session(python=DEFAULT_PYTHON_VERSION)
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/job/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,3 +1228,20 @@ def test_labels_setter(self):
job_config = self._make_one()
job_config.labels = labels
self.assertEqual(job_config._properties["labels"], labels)

def test_job_timeout_ms_raises_valueerror(self):
# Confirm that attempting to set a non-integer values will raise an Error.
with pytest.raises(ValueError):
# from google.cloud.bigquery import QueryJobConfig
chalmerlowe marked this conversation as resolved.
Show resolved Hide resolved
# job_config = QueryJobConfig()
job_config = self._make_one()
job_config.job_timeout_ms = "WillRaiseError"

def test_job_timeout_ms(self):
# Confirm that default status is None.
job_config = self._make_one()
assert job_config.job_timeout_ms is None

# Confirm that integers get converted to strings.
job_config.job_timeout_ms = 5000
assert job_config.job_timeout_ms == "5000" # int is converted to string