Skip to content

Commit

Permalink
docs: Explain Progress is not resumable if interrupted in docs FAQ (#…
Browse files Browse the repository at this point in the history
…2168)

* docs: Explain `Progress is not resumable if interrupted` in docs FAQ

* Use root package logger

* Add `pragma: no cover`

* Add test
  • Loading branch information
edgarrmondragon authored Jan 23, 2024
1 parent e61bade commit 47609eb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ class MyStream(Stream):
super().__init__(tap)
self.conn...
```

## I'm seeing `Note: Progress is not resumable if interrupted.` in my state files

If the stream attribute [`is_sorted`](singer_sdk.Stream.is_sorted) (default: `False`) is not set to `True`, the records are assumed not to be monotonically increasing, i.e. there's no guarantee that newer records always come later and the tap has to run to completion so the state can safely reflect the largest replication value seen. If you know that the records are monotonically increasing, you can set `is_sorted` to `True` and the sync will be resumable if it's interrupted at any point and the state file will reflect this.

```python
class MyStream(Stream):
is_sorted = True
```
8 changes: 8 additions & 0 deletions singer_sdk/helpers/_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import logging
import typing as t

from singer_sdk.exceptions import InvalidStreamSortException
Expand All @@ -17,6 +18,8 @@
SIGNPOST_MARKER = "replication_key_signpost"
STARTING_MARKER = "starting_replication_value"

logger = logging.getLogger("singer_sdk")


def get_state_if_exists(
tap_state: dict,
Expand Down Expand Up @@ -207,6 +210,11 @@ def increment_state(
stream_or_partition_state[PROGRESS_MARKERS] = {
PROGRESS_MARKER_NOTE: "Progress is not resumable if interrupted.",
}
logger.warning(
"Stream is assumed to be unsorted, progress is not resumable if "
"interrupted",
extra={"replication_key": replication_key},
)
progress_dict = stream_or_partition_state[PROGRESS_MARKERS]
old_rk_value = to_json_compatible(progress_dict.get("replication_key_value"))
new_rk_value = to_json_compatible(latest_record[replication_key])
Expand Down
24 changes: 24 additions & 0 deletions tests/core/test_state_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,27 @@ def test_state_finalize(dirty_state, finalized_state):
for partition_state in stream_state.get("partitions", []):
_state.finalize_state_progress_markers(partition_state)
assert state == finalized_state


def test_irresumable_state():
stream_state = {}
latest_record = {"updated_at": "2021-05-17T20:41:16Z"}
replication_key = "updated_at"
is_sorted = False
check_sorted = False

_state.increment_state(
stream_state,
latest_record=latest_record,
replication_key=replication_key,
is_sorted=is_sorted,
check_sorted=check_sorted,
)

assert stream_state == {
"progress_markers": {
"Note": "Progress is not resumable if interrupted.",
"replication_key": "updated_at",
"replication_key_value": "2021-05-17T20:41:16Z",
},
}

0 comments on commit 47609eb

Please sign in to comment.