Azure / azure-functions-durable-js

JavaScript library for using the Durable Functions bindings
https://www.npmjs.com/package/durable-functions
MIT License
128 stars 46 forks source link

Durable entity creation? (and lifecycle management) #557

Closed pcj closed 6 months ago

pcj commented 8 months ago

Hello, I'm just starting out with this framework and I'm really enjoying it, thanks.

Regarding entity functions, it seems they must all be predeclared at startup.

Is there a way to dynamically create new entities, or remove them over time? I would like to model a situation where I have an entity for every year/month/day in the future, but I don't want to statically generate all those entity functions for some predetermined length of time.

Am I thinking about this the wrong way?

pcj commented 8 months ago

After a bit more reading, my mental model is now that the registration function df.app.entity('gameState', handleEntityGameState) sets up a handler for a set of things of type gameState, where the EntityID determines the state for a particular player. You don't need to somehow predetermine the players beforehand.

From https://www.aaron-powell.com/posts/2019-09-27-using-durable-entities-and-orchestrators-to-create-an-api-cache/ it appears that DurableClient.readEntityState is used to determine if an entityId exists, and DurableClient.signalEntity will initialize one if not already exists.

If this is true, all great. I still don't see how to delete an entity from the API. Is it possible?

pcj commented 8 months ago

Okay, I think it see it now. To delete an entity, one would want to implement a delete operation and then call DurableEntityContext.destructOnExit().

lilyjma commented 6 months ago

Thanks for the raising issue @pcj. Since you seem to have figured out the problem, I'm closing this issue for now. Please feel free to reopen it if you have more questions regarding this topic.