-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[dagster-fivetran] Implement base poll method in FivetranClient #26060
Merged
maximearmstrong
merged 5 commits into
master
from
maxime/implement-base-poll-method-fivetran-client
Nov 27, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
56dea4f
[dagster-fivetran] Implement base poll method in FivetranClient
maximearmstrong 801dd9a
Remove unnecessary final call in poll method
maximearmstrong b101664
Add MIN_STR_TIME
maximearmstrong b4517b7
Add tests
maximearmstrong 4b0d41a
Update tests
maximearmstrong 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 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 |
---|---|---|
|
@@ -668,6 +668,61 @@ def _start_sync(self, request_fn: Callable[[], Mapping[str, Any]], connector_id: | |
" UI: " + connector.url | ||
) | ||
|
||
def poll_sync( | ||
self, | ||
connector_id: str, | ||
previous_sync_completed_at: datetime, | ||
poll_interval: float = DEFAULT_POLL_INTERVAL, | ||
poll_timeout: Optional[float] = None, | ||
) -> Mapping[str, Any]: | ||
"""Given a Fivetran connector and the timestamp at which the previous sync completed, poll | ||
until the next sync completes. | ||
|
||
The previous sync completion time is necessary because the only way to tell when a sync | ||
completes is when this value changes. | ||
|
||
Args: | ||
connector_id (str): The Fivetran Connector ID. You can retrieve this value from the | ||
"Setup" tab of a given connector in the Fivetran UI. | ||
previous_sync_completed_at (datetime.datetime): The datetime of the previous completed sync | ||
(successful or otherwise) for this connector, prior to running this method. | ||
poll_interval (float): The time (in seconds) that will be waited between successive polls. | ||
poll_timeout (float): The maximum time that will wait before this operation is timed | ||
out. By default, this will never time out. | ||
|
||
Returns: | ||
Dict[str, Any]: Parsed json data representing the API response. | ||
""" | ||
poll_start = datetime.now() | ||
while True: | ||
connector_details = self.get_connector_details(connector_id) | ||
connector = FivetranConnector.from_connector_details( | ||
connector_details=connector_details | ||
) | ||
self._log.info(f"Polled '{connector_id}'. Status: [{connector.sync_state}]") | ||
|
||
if connector.last_sync_completed_at > previous_sync_completed_at: | ||
break | ||
|
||
if poll_timeout and datetime.now() > poll_start + timedelta(seconds=poll_timeout): | ||
raise Failure( | ||
f"Sync for connector '{connector_id}' timed out after " | ||
f"{datetime.now() - poll_start}." | ||
) | ||
|
||
# Sleep for the configured time interval before polling again. | ||
time.sleep(poll_interval) | ||
|
||
if not connector.is_last_sync_successful: | ||
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. [2] |
||
raise Failure( | ||
f"Sync for connector '{connector_id}' failed!", | ||
metadata={ | ||
"connector_details": MetadataValue.json(connector_details), | ||
"log_url": MetadataValue.url(connector.url), | ||
}, | ||
) | ||
return connector_details | ||
|
||
|
||
@experimental | ||
class FivetranWorkspace(ConfigurableResource): | ||
|
This file contains 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 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
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.
[1]