hollywood icon indicating copy to clipboard operation
hollywood copied to clipboard

Added Registry Features

Open stevohuncho opened this issue 2 years ago • 4 comments

Features Added

  • Search for PID by registry ID
  • Get all registry IDs

Reasoning

Makes it easy to grab all running actors to aid in frontend representation, etc.

stevohuncho avatar Sep 06 '23 19:09 stevohuncho

I suggest the we close this PR. It'll be quite a lot of work to clean it up and we don't have a use-case for it.

@stevohuncho: When forking a repo, please don't modify the import paths. You don't need to do that as the Go module system will use your local copies if they are available.

Also, for the PR to be considered it should have an issue, opened ahead of time which lays out what problem the PR will try to solve. That way we can evaluate the proposed changes seeing the implementations.

perbu avatar Nov 29 '23 09:11 perbu

My issue and reasoning for opening this was at the time of opening there is no way to access the IDs of the active PIDs. I am using this for task management on my backend, and to represent this to the frontend of the user I could not find a better way to get the values of all the PIDs' IDs in the registry. Is there a better method now?

stevohuncho avatar Nov 29 '23 14:11 stevohuncho

My issue and reasoning for opening this was at the time of opening there is no way to access the IDs of the active PIDs. I am using this for task management on my backend, and to represent this to the frontend of the user I could not find a better way to get the values of all the PIDs' IDs in the registry. Is there a better method now?

You can create an actor and listen to EventStream. Inside that actor you can listen for events when an actor starts/stops. This way you can have stats and expose them the way you want.

tprifti avatar Nov 30 '23 11:11 tprifti

This was the only code I added (other files changed was the change in package names to my fork which i didn't realize was still tied to this PR). It just added QoL for the privated parameters in the registry. These are just read commands so there is no possible way the user can mess with the registry either. Not sure why I should go through a more complicated method when this is a simple solution that just exposes safe reading to a privated parameter. I have been using this fork in my project and have encountered zero issues. Also I just reverted the package names back to anthdm instead of my fork.

func (r *Registry) GetIDs() []string {
	r.mu.RLock()
	defer r.mu.RUnlock()
	keys := make([]string, 0, len(r.lookup))
	for k := range r.lookup {
		keys = append(keys, k)
	}
	return keys
}

func (r *Registry) GetPIDs() []*PID {
	r.mu.RLock()
	defer r.mu.RUnlock()
	keys := make([]*PID, 0, len(r.lookup))
	for _, v := range r.lookup {
		keys = append(keys, v.PID())
	}
	return keys
}

func (r *Registry) Search(id string) (*PID, error) {
	r.mu.RLock()
	defer r.mu.RUnlock()
	for k, v := range r.lookup {
		if k == id {
			return v.PID(), nil
		}
	}
	return nil, fmt.Errorf("failed to find id in registry")
}

stevohuncho avatar Nov 30 '23 15:11 stevohuncho