amoghrajesh commented on code in PR #75272:
URL: https://github.com/apache/airflow/pull/75272#discussion_r4410460610
##########
providers/microsoft/azure/src/airflow/providers/microsoft/azure/operators/powerbi.py:
##########
@@ -172,19 +193,27 @@ def get_job_status(self, external_id: JsonValue, context:
Context) -> str:
return refresh_details[PowerBIDatasetRefreshFields.STATUS.value]
def is_job_active(self, status: str) -> bool:
- return status == PowerBIDatasetRefreshStatus.IN_PROGRESS
+ # Without wait_for_completion a retry does not wait for a refresh in
progress either:
+ # is_job_succeeded counts it as done.
+ return self.wait_for_completion and status ==
PowerBIDatasetRefreshStatus.IN_PROGRESS
def is_job_succeeded(self, status: str) -> bool:
- return status == PowerBIDatasetRefreshStatus.COMPLETED
+ if status == PowerBIDatasetRefreshStatus.COMPLETED:
+ return True
+ # Without wait_for_completion the task only has to start the refresh,
so one in progress counts
+ # as done. The mixin then logs it as completed and counts it in
resumable_job.already_succeeded,
+ # but only this path pushes the refresh id: the mixin reconnects to an
active job through
+ # poll_until_complete alone, without get_job_result.
Review Comment:
```suggestion
# Without wait_for_completion, is_job_succeeded counts an
in-progress refresh as done.
```
##########
providers/microsoft/azure/src/airflow/providers/microsoft/azure/operators/msgraph.py:
##########
@@ -332,16 +352,42 @@ def push_page(
"""
cursor = self.get_cursor(task_state_store)
page = cursor["pages"] if cursor else 0
- task_state_store.set(f"{PAGE_KEY_PREFIX}{page}", result)
+ task_state_store.set(f"{_PAGE_KEY_PREFIX}{page}", {"result": result})
task_state_store.set(
- CURSOR_KEY,
+ _CURSOR_KEY,
{
"url": deferred.trigger.url,
"query_parameters": (deferred.kwargs or
{}).get("query_parameters"),
"pages": page + 1,
},
)
+ def clean_up(self, task_state_store: TaskStateStoreAccessor, results: Any)
-> None:
+ """
+ Remove the pages and the cursor from the task state store once the
result is returned.
+
+ The result of a request that is not a GET stays, so a retry returns it
instead of sending the
+ request again. It goes in before the pages are removed, so a crash in
between does not send the
+ request again either.
+ """
Review Comment:
```suggestion
"""
Remove the pages and the cursor from the task state store once the
result is returned.
A non GET result is written before the pages go, so a crash in
between does not resend the request.
"""
```
##########
providers/microsoft/azure/src/airflow/providers/microsoft/azure/operators/msgraph.py:
##########
@@ -332,16 +352,42 @@ def push_page(
"""
cursor = self.get_cursor(task_state_store)
page = cursor["pages"] if cursor else 0
- task_state_store.set(f"{PAGE_KEY_PREFIX}{page}", result)
+ task_state_store.set(f"{_PAGE_KEY_PREFIX}{page}", {"result": result})
task_state_store.set(
- CURSOR_KEY,
+ _CURSOR_KEY,
{
"url": deferred.trigger.url,
"query_parameters": (deferred.kwargs or
{}).get("query_parameters"),
"pages": page + 1,
},
)
+ def clean_up(self, task_state_store: TaskStateStoreAccessor, results: Any)
-> None:
Review Comment:
```suggestion
def _clean_up(self, task_state_store: TaskStateStoreAccessor, results:
Any) -> None:
```
##########
providers/microsoft/azure/src/airflow/providers/microsoft/azure/operators/msgraph.py:
##########
@@ -300,8 +305,8 @@ def execute_complete(
results = result
elif task_state_store:
results = self.pull_pages(task_state_store)
- if task_state_store and self.method.upper() != "GET":
- task_state_store.set(COMPLETED_KEY, {"result": results})
+ if task_state_store:
+ self.clean_up(task_state_store, results=results)
Review Comment:
```suggestion
self._clean_up(task_state_store, results=results)
```
##########
providers/microsoft/azure/src/airflow/providers/microsoft/azure/operators/msgraph.py:
##########
@@ -332,16 +352,42 @@ def push_page(
"""
cursor = self.get_cursor(task_state_store)
page = cursor["pages"] if cursor else 0
- task_state_store.set(f"{PAGE_KEY_PREFIX}{page}", result)
+ task_state_store.set(f"{_PAGE_KEY_PREFIX}{page}", {"result": result})
task_state_store.set(
- CURSOR_KEY,
+ _CURSOR_KEY,
{
"url": deferred.trigger.url,
"query_parameters": (deferred.kwargs or
{}).get("query_parameters"),
"pages": page + 1,
},
)
+ def clean_up(self, task_state_store: TaskStateStoreAccessor, results: Any)
-> None:
+ """
+ Remove the pages and the cursor from the task state store once the
result is returned.
+
+ The result of a request that is not a GET stays, so a retry returns it
instead of sending the
+ request again. It goes in before the pages are removed, so a crash in
between does not send the
+ request again either.
+ """
+ if self.method.upper() != "GET":
+ task_state_store.set(_COMPLETED_KEY, {"result": results})
+ self.remove_pages(task_state_store, self.get_cursor(task_state_store))
Review Comment:
```suggestion
self._remove_pages(task_state_store,
self.get_cursor(task_state_store))
```
##########
providers/microsoft/azure/src/airflow/providers/microsoft/azure/operators/msgraph.py:
##########
@@ -332,16 +352,42 @@ def push_page(
"""
cursor = self.get_cursor(task_state_store)
page = cursor["pages"] if cursor else 0
- task_state_store.set(f"{PAGE_KEY_PREFIX}{page}", result)
+ task_state_store.set(f"{_PAGE_KEY_PREFIX}{page}", {"result": result})
task_state_store.set(
- CURSOR_KEY,
+ _CURSOR_KEY,
{
"url": deferred.trigger.url,
"query_parameters": (deferred.kwargs or
{}).get("query_parameters"),
"pages": page + 1,
},
)
+ def clean_up(self, task_state_store: TaskStateStoreAccessor, results: Any)
-> None:
+ """
+ Remove the pages and the cursor from the task state store once the
result is returned.
+
+ The result of a request that is not a GET stays, so a retry returns it
instead of sending the
+ request again. It goes in before the pages are removed, so a crash in
between does not send the
+ request again either.
+ """
+ if self.method.upper() != "GET":
+ task_state_store.set(_COMPLETED_KEY, {"result": results})
+ self.remove_pages(task_state_store, self.get_cursor(task_state_store))
+
+ @staticmethod
+ def remove_pages(task_state_store: TaskStateStoreAccessor, cursor:
_PaginationCursor | None) -> None:
Review Comment:
```suggestion
def _remove_pages(task_state_store: TaskStateStoreAccessor, cursor:
_PaginationCursor | None) -> None:
```
##########
providers/microsoft/azure/src/airflow/providers/microsoft/azure/operators/msgraph.py:
##########
@@ -310,15 +315,30 @@ def get_task_state_store(self, context: Context) ->
TaskStateStoreAccessor | Non
return context.get("task_state_store") if self.durable else None
@staticmethod
- def get_cursor(task_state_store: TaskStateStoreAccessor) ->
PaginationCursor | None:
- return cast("PaginationCursor | None",
task_state_store.get(CURSOR_KEY))
+ def get_cursor(task_state_store: TaskStateStoreAccessor) ->
_PaginationCursor | None:
+ return cast("_PaginationCursor | None",
task_state_store.get(_CURSOR_KEY))
def pull_pages(self, task_state_store: TaskStateStoreAccessor) ->
list[Any]:
- """Return the results of the pages processed so far, kept in the task
state store."""
+ """
+ Return the results of the pages processed so far, kept in the task
state store.
+
+ A page is kept wrapped in a dict, so a page whose result is ``None``
is told apart from a page
+ that is gone, for instance because it expired under ``[state_store]
default_retention_days``.
+ A missing page removes the pages and the cursor, so the next try
starts again from the first page
+ instead of returning results with a hole in them. So does a page that
is not wrapped, which
+ 15.3.0 kept before a provider upgrade.
+ """
results: list[Any] = []
cursor = self.get_cursor(task_state_store)
for page in range(cursor["pages"] if cursor else 0):
- self.append_result(results=results,
result=task_state_store.get(f"{PAGE_KEY_PREFIX}{page}"))
+ kept = task_state_store.get(f"{_PAGE_KEY_PREFIX}{page}")
+ if not isinstance(kept, dict) or "result" not in kept:
+ self.remove_pages(task_state_store, cursor)
Review Comment:
```suggestion
self._remove_pages(task_state_store, cursor)
```
##########
providers/microsoft/azure/src/airflow/providers/microsoft/azure/operators/powerbi.py:
##########
@@ -172,19 +193,27 @@ def get_job_status(self, external_id: JsonValue, context:
Context) -> str:
return refresh_details[PowerBIDatasetRefreshFields.STATUS.value]
def is_job_active(self, status: str) -> bool:
- return status == PowerBIDatasetRefreshStatus.IN_PROGRESS
+ # Without wait_for_completion a retry does not wait for a refresh in
progress either:
+ # is_job_succeeded counts it as done.
+ return self.wait_for_completion and status ==
PowerBIDatasetRefreshStatus.IN_PROGRESS
def is_job_succeeded(self, status: str) -> bool:
- return status == PowerBIDatasetRefreshStatus.COMPLETED
+ if status == PowerBIDatasetRefreshStatus.COMPLETED:
+ return True
+ # Without wait_for_completion the task only has to start the refresh,
so one in progress counts
+ # as done. The mixin then logs it as completed and counts it in
resumable_job.already_succeeded,
+ # but only this path pushes the refresh id: the mixin reconnects to an
active job through
+ # poll_until_complete alone, without get_job_result.
+ return not self.wait_for_completion and status ==
PowerBIDatasetRefreshStatus.IN_PROGRESS
def poll_until_complete(self, external_id: JsonValue, context: Context) ->
None:
dataset_refresh_id = str(external_id)
- self._push_refresh_xcom(context, dataset_refresh_id)
-
if not self.wait_for_completion:
+ # get_job_result pushes the refresh id, the mixin calls it next.
Review Comment:
```suggestion
# get_job_result pushes the refresh id.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]