Skip to content

Commit

Permalink
Allow setting the pooling time in DLPHook (#8824)
Browse files Browse the repository at this point in the history
Co-authored-by: Kamil Breguła <[email protected]>
Co-authored-by: Ash Berlin-Taylor <[email protected]>
  • Loading branch information
3 people committed May 19, 2020
1 parent 2121f49 commit 841d816
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions airflow/providers/google/cloud/hooks/dlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
from airflow.providers.google.common.hooks.base_google import GoogleBaseHook

DLP_JOB_PATH_PATTERN = "^projects/[^/]+/dlpJobs/(?P<job>.*?)$"
# Time to sleep between active checks of the operation results
TIME_TO_SLEEP_IN_SECONDS = 1


# pylint: disable=R0904, C0302
Expand Down Expand Up @@ -180,6 +178,7 @@ def create_dlp_job(
timeout: Optional[float] = None,
metadata: Optional[Sequence[Tuple[str, str]]] = None,
wait_until_finished: bool = True,
time_to_sleep_in_seconds: int = 60
) -> DlpJob:
"""
Creates a new job to inspect storage or calculate risk metrics.
Expand Down Expand Up @@ -207,6 +206,9 @@ def create_dlp_job(
until it is set to DONE.
:type wait_until_finished: bool
:rtype: google.cloud.dlp_v2.types.DlpJob
:param time_to_sleep_in_seconds: (Optional) Time to sleep, in seconds, between active checks
of the operation results. Defaults to 60.
:type time_to_sleep_in_seconds: int
"""

client = self.get_conn()
Expand Down Expand Up @@ -242,7 +244,7 @@ def create_dlp_job(
DlpJob.JobState.RUNNING,
DlpJob.JobState.JOB_STATE_UNSPECIFIED,
]:
time.sleep(TIME_TO_SLEEP_IN_SECONDS)
time.sleep(time_to_sleep_in_seconds)
else:
raise AirflowException(
"Stopped polling DLP job state. DLP job {} state: {}.".format(
Expand Down

0 comments on commit 841d816

Please sign in to comment.