golemfactory/golem-core-python

Improve the events design

Opened this issue · 0 comments

This is a wide topic that should spawn several tasks.

Now we have events NewResource, ResourceClosed, ResorceDataChanged and never-emitted ResourceChangePossible.
This is not enough. But: it's super important to add only really useful events now, not "all events that maybe-one-day-could-have-some-use-and-we-thought-of-them-today".

Changes that seem reasonable to me now:

  • Remove ResourceChangePossible. This will be super-complex to implement and doesn't seem very useful either way. Go back to the concept if we ever decide we need it.

  • Add events ShutdownStarted, ShutdownFinished - this will make debugging easier (e.g. check if there was a full clean shutdown, check what happened during the shutdown and what happened just before etc). Consider also GolemStarted event, but I'm not sure about this one.

  • Add BatchFinished event. Or, as an alternative: maybe emit ResourceClosed(batch)? But this might be confusing.

  • Consider splitting NewResource to ResourceCreated and ResourceFound ("we created a new Resource object that corresponds to a Golem entity that was created before", e.g. when we first time interact with an Allocation created in a previous run). Consider following scenario:

    1. We register an event callback that is supposed to run whenever we create a new activity
    2. We create an Activity, callback is executed
    3. We restart the app
    4. We get a DebitNote for this activity and the callback executes again, because Activity object was created (but we didn't create an activity, GolemNode was told about a previously created activity)

    We might consider event nesting here - ResourceCreated and ResourceFound inheriting from NewResource.