Skip to content

Conversation

@Mantisus
Copy link
Collaborator

Description

Add Actor method use_state. Allows the user to save data and states in kvs with periodic persistence.

Issues

Closes: #735

Testing

Added unit tests

@Mantisus Mantisus requested review from Pijukatel and vdusek January 16, 2026 00:14
@Mantisus Mantisus self-assigned this Jan 16, 2026
@vdusek
Copy link
Contributor

vdusek commented Jan 16, 2026

Let's please wait until the implementation is clarified in #735.

Copy link
Contributor

@vdusek vdusek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new use_state method to the Actor class, enabling users to easily create and manage state values that are automatically persisted to key-value stores. The state is persisted periodically (based on PERSIST_STATE_INTERVAL_MILLIS) and also when the Actor exits.

Changes:

  • Added Actor.use_state() method for managing persistent state
  • Implemented automatic state persistence on Actor exit via _save_actor_state()
  • Added comprehensive unit tests covering default and custom configurations

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
src/apify/_actor.py Implements the use_state method, adds state store tracking, and integrates state persistence into Actor lifecycle
tests/unit/actor/test_actor_key_value_store.py Adds unit tests for the new use_state functionality with various scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vdusek
Copy link
Contributor

vdusek commented Jan 26, 2026

quite good comments from copilot 🙂

Copy link
Contributor

@vdusek vdusek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks for resolving those comments from Copilot, LGTM from my side, let's wait for @Pijukatel and merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider adding Actor.use_state

2 participants