diff --git a/knowledge_base/failing_job_examples/resources/invalid_configuration.job.yml b/knowledge_base/failing_job_examples/resources/invalid_configuration.job.yml index 71cdf3c..e311969 100644 --- a/knowledge_base/failing_job_examples/resources/invalid_configuration.job.yml +++ b/knowledge_base/failing_job_examples/resources/invalid_configuration.job.yml @@ -9,7 +9,7 @@ resources: max_concurrent_runs: 1 parameters: - name: batch_size - default: "0" + default: "250" tasks: - task_key: validate_configuration max_retries: 0 diff --git a/knowledge_base/failing_job_examples/src/invalid_configuration.py b/knowledge_base/failing_job_examples/src/invalid_configuration.py index 51ea9fd..9b60ff4 100644 --- a/knowledge_base/failing_job_examples/src/invalid_configuration.py +++ b/knowledge_base/failing_job_examples/src/invalid_configuration.py @@ -1,14 +1,24 @@ # Databricks notebook source -batch_size_value = dbutils.widgets.get("batch_size") +def parse_positive_batch_size(value): + """Parse *value* as a positive integer batch size. + + Raises ValueError with a descriptive message if *value* cannot be + converted to an integer or is not greater than zero. + """ + try: + batch_size = int(value) + except ValueError: + raise ValueError( + f"Invalid job configuration: batch_size must be an integer, found {value!r}" + ) from None + + if batch_size <= 0: + raise ValueError( + f"Invalid job configuration: batch_size must be greater than zero, found {batch_size}" + ) -try: - batch_size = int(batch_size_value) -except ValueError: - raise ValueError( - f"Invalid job configuration: batch_size must be an integer, found {batch_size_value!r}" - ) from None - -if batch_size <= 0: - raise ValueError( - f"Invalid job configuration: batch_size must be greater than zero, found {batch_size}" - ) + return batch_size + + +batch_size_value = dbutils.widgets.get("batch_size") +batch_size = parse_positive_batch_size(batch_size_value)