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.
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.
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.
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.
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.
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.
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.
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 <92638966+TC-MO@users.noreply.github.com>
|
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.