-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Introduce a base class for aws triggers #32274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2c91023
introduce a base class for aws triggers
vandonr-amz 8814192
adapt tests
vandonr-amz c567e54
write serializer tests for all migrated triggers
vandonr-amz dacb392
mark dumb implem as not a test class
vandonr-amz e48174c
add base to provider yaml
vandonr-amz 5c3d58b
fix optional types stuff
vandonr-amz 3cf3f23
Merge remote-tracking branch 'origin/main' into vandonr/deferrable
vandonr-amz 2337cc8
remove unnecessary None type & update doc a bit
vandonr-amz d64c4ac
rename file
vandonr-amz 7f8683b
docstring update to specify fields that are auto-serialized
vandonr-amz 941da9a
docstring fixes
vandonr-amz bb065f8
make comment inclusive
vandonr-amz 0f6a9f5
fix
vandonr-amz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,61 +16,43 @@ | |
| # under the License. | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| from airflow.providers.amazon.aws.hooks.athena import AthenaHook | ||
| from airflow.providers.amazon.aws.utils.waiter_with_logging import async_wait | ||
| from airflow.triggers.base import BaseTrigger, TriggerEvent | ||
| from airflow.providers.amazon.aws.hooks.base_aws import AwsGenericHook | ||
| from airflow.providers.amazon.aws.triggers.base import AwsBaseWaiterTrigger | ||
|
|
||
|
|
||
| class AthenaTrigger(BaseTrigger): | ||
| class AthenaTrigger(AwsBaseWaiterTrigger): | ||
| """ | ||
| Trigger for RedshiftCreateClusterOperator. | ||
|
|
||
| The trigger will asynchronously poll the boto3 API and wait for the | ||
| Redshift cluster to be in the `available` state. | ||
|
|
||
| :param query_execution_id: ID of the Athena query execution to watch | ||
| :param poll_interval: The amount of time in seconds to wait between attempts. | ||
| :param max_attempt: The maximum number of attempts to be made. | ||
| :param waiter_delay: The amount of time in seconds to wait between attempts. | ||
| :param waiter_max_attempts: The maximum number of attempts to be made. | ||
| :param aws_conn_id: The Airflow connection used for AWS credentials. | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| query_execution_id: str, | ||
| poll_interval: int, | ||
| max_attempt: int, | ||
| waiter_delay: int, | ||
| waiter_max_attempts: int, | ||
|
Comment on lines
-42
to
+41
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this trigger was added in #32186 merged on June 27th, last provider release was on June 20th, so this breaking change is OK. |
||
| aws_conn_id: str, | ||
| ): | ||
| self.query_execution_id = query_execution_id | ||
| self.poll_interval = poll_interval | ||
| self.max_attempt = max_attempt | ||
| self.aws_conn_id = aws_conn_id | ||
|
|
||
| def serialize(self) -> tuple[str, dict[str, Any]]: | ||
| return ( | ||
| self.__class__.__module__ + "." + self.__class__.__qualname__, | ||
| { | ||
| "query_execution_id": str(self.query_execution_id), | ||
| "poll_interval": str(self.poll_interval), | ||
| "max_attempt": str(self.max_attempt), | ||
| "aws_conn_id": str(self.aws_conn_id), | ||
| }, | ||
| super().__init__( | ||
| serialized_fields={"query_execution_id": query_execution_id}, | ||
| waiter_name="query_complete", | ||
| waiter_args={"QueryExecutionId": query_execution_id}, | ||
| failure_message=f"Error while waiting for query {query_execution_id} to complete", | ||
| status_message=f"Query execution id: {query_execution_id}", | ||
| status_queries=["QueryExecution.Status"], | ||
| return_value=query_execution_id, | ||
| waiter_delay=waiter_delay, | ||
| waiter_max_attempts=waiter_max_attempts, | ||
| aws_conn_id=aws_conn_id, | ||
| ) | ||
|
|
||
| async def run(self): | ||
| hook = AthenaHook(self.aws_conn_id) | ||
| async with hook.async_conn as client: | ||
| waiter = hook.get_waiter("query_complete", deferrable=True, client=client) | ||
| await async_wait( | ||
| waiter=waiter, | ||
| waiter_delay=self.poll_interval, | ||
| waiter_max_attempts=self.max_attempt, | ||
| args={"QueryExecutionId": self.query_execution_id}, | ||
| failure_message=f"Error while waiting for query {self.query_execution_id} to complete", | ||
| status_message=f"Query execution id: {self.query_execution_id}, " | ||
| "Query is still in non-terminal state", | ||
| status_args=["QueryExecution.Status.State"], | ||
| ) | ||
| yield TriggerEvent({"status": "success", "value": self.query_execution_id}) | ||
| def hook(self) -> AwsGenericHook: | ||
| return AthenaHook(self.aws_conn_id) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a somewhat unrelated fix that allows specifying a sleep time of 0 in unit tests. Without this, athena unit tests were taking 30s each
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, but you can also just mock the sleep function no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just setting sleep_time=0 is sooo much simpler & cleaner & easier to read