-
Notifications
You must be signed in to change notification settings - Fork 157
docs: State persistence update #2176
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,9 +47,9 @@ By default, an Actor keeps its state in the server's memory. During a server swi | |
|
|
||
| ## Implementing state persistence | ||
|
|
||
| The [Apify SDKs](/sdk) handle state persistence automatically. | ||
| To handle state persistence, use the [`Actor.useState()`](/sdk/js/reference/class/Actor#useState) method. This method automatically saves and retrieves your state during migrations. | ||
|
|
||
| This is done using the `Actor.on()` method and the `migrating` event. | ||
| For more control or when using Python, you can manually handle state persistence using the `Actor.on()` method and the `migrating` event. | ||
|
|
||
| - The `migrating` event is triggered just before a migration occurs, allowing you to save your state. | ||
| - To retrieve previously saved state, you can use the [`Actor.getValue`](/sdk/js/reference/class/Actor#getValue)/[`Actor.get_value`](/sdk/python/reference/class/Actor#get_value) methods. | ||
|
Member
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. It is kinda bad to recommend many different ways to do this. How about:
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. Ok, let's wait for the Python team. I've subscribed to the issue, will finalize this once the Python issue is resolved. |
||
|
|
||
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.
What control? More than what? And why we move straight to Python from the control bit what is the connection?
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.
Unrelated to the PR: Hmm, the Python thing is kinda bummer. Seems we have it in Crawlee but not SDK. We should add it there @Pijukatel
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 added the issue apify/apify-sdk-python#735
But we have to think this through, given the recent (and maybe upcoming) changes to the use state
apify/crawlee#3309
apify/crawlee-python#1669
Should
Actor.use_statepoint to a different state thanCrawler.use_stateunless explicitly set up to share the same state? If we by default separateuse_stateof two different crawlers, then it will be different from actor as well.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 determined by the KV record key which is one of the parameters of useState.
If users use this and Crawler.useState, I think those should be 2 separate instances with 2 different default keys. But there isn't much use-case for this and if users combine a lot of these, they are asking for trouble.