subbota19 opened a new pull request, #46672:
URL: https://github.com/apache/airflow/pull/46672
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
<!-- Please keep an empty line above the dashes. -->
---
Fix https://github.com/apache/airflow/issues/46648.
**Problem Description**
In deferable mode, Airflow uses triggers to check the job status, so every
time the deferable interval is reached, it checks the status and yields an
event on [this
line](https://github.com/apache/airflow/blob/main/providers/snowflake/src/airflow/providers/snowflake/triggers/snowflake_trigger.py#L89).
However, when not using deferable logic, the execution follows the [else
statement](https://github.com/apache/airflow/blob/main/providers/snowflake/src/airflow/providers/snowflake/operators/snowflake.py#L456),
which does not include a while loop to continuously monitor execution.
Instead, on [this
line](https://github.com/apache/airflow/blob/main/providers/snowflake/src/airflow/providers/snowflake/operators/snowflake.py#L457),
the task iterates through active Snowflake jobs, checks their status and then
sleeps for _poll_interval_.
This results in the following behavior:
✅ If a job finishes in less than 5 seconds ( _time.sleep_ using the default
_poll_interval_), the logic works correctly.
❌ If a job takes longer than 5 seconds, there is no mechanism to keep
monitoring it, and the task incorrectly finishes after the loop ends - even if
the Snowflake job is still running.
**Suggested Fix**
I propose adding a running status check inside **poll_on_queries** and
modifying the else statement with a loop to ensure Airflow waits until all
queries finish, the logic is quick similar to what we use in [deferable trigger
while
loop](https://github.com/subbota19/airflow/blob/main/providers/snowflake/src/airflow/providers/snowflake/triggers/snowflake_trigger.py#L79)
With this change, the Airflow task would periodically call
**poll_on_queries** and continue waiting until all jobs are complete.
**Tests**
Simulates a scenario where the Snowflake job is running for two checks (10
seconds apart, assuming default _poll_interval_): ffter the second check, the
job is completed successfully and task is marked as successful.
Simulates a scenario where the Snowflake job failed and ensures
AirflowException is raised.
--
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]