Skip to content

Commit

Permalink
fix(sdks/actor/runtime): fix initialize getBatch not reading keys cor…
Browse files Browse the repository at this point in the history
…rectly
  • Loading branch information
NathanFlurry committed Dec 30, 2024
1 parent 5fbd290 commit b0a5e59
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions sdks/actor/runtime/src/actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ export abstract class Actor<

// Write to KV
await this.#ctx.kv.put(KEYS.STATE.DATA, this.#stateRaw);

logger().debug("state saved");
});
}

Expand Down Expand Up @@ -253,13 +255,18 @@ export abstract class Actor<
}
assertExists(this._onInitialize);

// HACK(RVT-4150): `get` does not work for arrays
// Read initial state
const getStateBatch = await this.#ctx.kv.getBatch([
//const [initialized, stateData] = await this.#ctx.kv.getBatch<[boolean, state]>([
// KEYS.STATE.INITIALIZED,
// KEYS.STATE.DATA,
//]);
const getStateBatch = Object.fromEntries(await this.#ctx.kv.getBatch([
KEYS.STATE.INITIALIZED,
KEYS.STATE.DATA,
]);
const initialized = getStateBatch.get(KEYS.STATE.INITIALIZED) as boolean;
const stateData = getStateBatch.get(KEYS.STATE.DATA) as State;
]));
const initialized = getStateBatch[String(KEYS.STATE.INITIALIZED)] as boolean;
const stateData = getStateBatch[String(KEYS.STATE.DATA)] as State;

if (!initialized) {
// Initialize
Expand Down

0 comments on commit b0a5e59

Please sign in to comment.