Implement token refresh on BigQuery dts run operator to handle the heavy migration jobs over 1 hour#37538
Implement token refresh on BigQuery dts run operator to handle the heavy migration jobs over 1 hour#37538okayhooni wants to merge 1 commit into
Conversation
| current_tick_div, current_tick_mod = divmod(idx * interval, self.token_refresh_interval_seconds) | ||
| next_tick_div, next_tick_mod = divmod((idx + 1) * interval, self.token_refresh_interval_seconds) | ||
| if (current_tick_div < next_tick_div and 0 < next_tick_mod) or ( | ||
| current_tick_mod == 0 and 1 <= current_tick_div | ||
| ): | ||
| _ = self.hook.refresh_credentials() | ||
| self.log.info( | ||
| f"Credentials were refreshed on tick: idx={idx}, idx*interval={idx * interval} sec" | ||
| ) |
There was a problem hiding this comment.
Other providers also requires refresh logic but seems like they have simpler implementation. For example:
airflow/airflow/providers/databricks/hooks/databricks_base.py
Lines 441 to 453 in 0b680c9
Can you explain why we need complex logic here?
Also please extract the check validation (time handling) to it's own private function - it should be covered by unit tests
There was a problem hiding this comment.
Thank you for quick and detailed review..!
Actually, I can't find the token validation method on base_google.py module, as like databricks_base.py module you mentioned.. If it has similar method based on Google sdk, it will be more simple and elegant way, as you said. But, it tasks more GCP API calls to check token validity on every loop (+ Is it possible to check token validity or refresh token with already expired credential token..?)
We experienced some error cases, even though the tasks take just over 30 minutes, not 1 hour, with same authorization error. (I don't know why..) so I decided to use the half of default token lifespan to refresh token.
|
I got the same authorization error even after applying this refresh logic.. So, I close it. |
|
cc @VladaZakharova maybe something worth investigating |
related issue:
releated PR:
Currently, when BigQuery Data Transfer job triggered by Airflow operator, exceeds one hour, it fails due to the expiration of the credential (default lifespan = 1 hour).
So, I add the token refresh logic on DTS run operator. (additionally, add fallback logic to
timeoutparameter based onexecution_timeoutof Operator)