Skip to content

Commit 96ceef6

Browse files
authored
fix: type error in statistics persist state (#206)
### Description - fix: type error in statistics persist state ### Related issues - Closes: #194 ### Testing - N/A ### Checklist - [x] Changes are described in the `CHANGELOG.md` - [x] CI passed
1 parent 849d73c commit 96ceef6

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
- Add storage-related helpers `get_data`, `push_data` and `export_to` to `BasicCrawler` and `BasicContext`
1616
- Add `PlaywrightCrawler`'s enqueue links helper
1717

18+
### Fixes
19+
20+
- Fix type error in persist state of statistics
21+
1822
## [0.0.4](../../releases/tag/v0.0.4) - 2024-05-30
1923

2024
- Another internal release, adding statistics capturing, proxy configuration and

src/crawlee/statistics/statistics.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from crawlee._utils.recurring_task import RecurringTask
1212
from crawlee.events import LocalEventManager
13-
from crawlee.events.types import Event
13+
from crawlee.events.types import Event, EventPersistStateData
1414
from crawlee.statistics import FinalStatistics, StatisticsPersistedState, StatisticsState
1515
from crawlee.statistics.error_tracker import ErrorTracker
1616
from crawlee.storages import KeyValueStore
@@ -126,7 +126,7 @@ async def __aexit__(
126126
self.state.crawler_finished_at = datetime.now(timezone.utc)
127127
self._events.off(event=Event.PERSIST_STATE, listener=self._persist_state)
128128
await self._periodic_logger.stop()
129-
await self._persist_state()
129+
await self._persist_state(event_data=EventPersistStateData(is_migrating=False))
130130

131131
def register_status_code(self, code: int) -> None:
132132
"""Increment the number of times a status code has been received."""
@@ -233,7 +233,9 @@ async def _maybe_load_statistics(self) -> None:
233233
elif saved_state.crawler_last_started_at:
234234
self._instance_start = saved_state.crawler_last_started_at
235235

236-
async def _persist_state(self) -> None:
236+
async def _persist_state(self, event_data: EventPersistStateData) -> None:
237+
logger.debug(f'Persisting state of the Statistics (event_data={event_data}).')
238+
237239
if not self._persistence_enabled:
238240
return
239241

src/crawlee/storages/request_queue.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ class RequestQueue(BaseStorage, RequestProvider):
5252
rq = await RequestQueue.open(id='my_rq_id')
5353
"""
5454

55-
_API_PROCESSED_REQUESTS_DELAY = timedelta(seconds=10)
55+
# TODO: set this back to 10 seconds once the following issue is resolved:
56+
# https://github.com/apify/crawlee-python/issues/203
57+
_API_PROCESSED_REQUESTS_DELAY = timedelta(seconds=1)
5658
"""Delay threshold to assume consistency of queue head operations after queue modifications."""
5759

5860
_MAX_CACHED_REQUESTS = 1_000_000

0 commit comments

Comments
 (0)