-
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?
Conversation
|
Preview for this PR was built for commit |
sources/platform/actors/development/builds_and_runs/state_persistence.md
Outdated
Show resolved
Hide resolved
| The simplest way to handle state persistence is with the [`Actor.useState`](/sdk/js/reference/class/Actor#useState) method, which 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. |
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_state point to a different state than Crawler.use_state unless explicitly set up to share the same state? If we by default separate use_state of 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.
| The simplest way to handle state persistence is with the [`Actor.useState`](/sdk/js/reference/class/Actor#useState) method, which 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. |
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
| 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. |
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.
It is kinda bad to recommend many different ways to do this. How about:
- Let's wait for Python team to add
use_stateto SDK if it is reasonably easy - Recommend it as a primary method of handling state, we don't even need to mention getValue then.
- Show
useStatein the first code example - Keep the "manual" usage for the 2nd example with the reboot (I want this to be automatically in the SDK too but that won't happen soon)
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.
Ok, let's wait for the Python team. I've subscribed to the issue, will finalize this once the Python issue is resolved.
…istence.md Co-authored-by: Michał Olender <[email protected]>
|
Preview for this PR was built for commit |
Note
Refines guidance on Actor state persistence.
Actor.useStatefor automatic state save/restore during migrationsActor.on()migratingevent and retrieval withActor.getValue/Actor.get_value, noting Python usagestate_persistence.md; no code changesWritten by Cursor Bugbot for commit c9753ae. Configure here.