Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement EboActorsManager #25

Merged
merged 7 commits into from
Aug 20, 2024
Merged

feat: implement EboActorsManager #25

merged 7 commits into from
Aug 20, 2024

Conversation

0xyaco
Copy link
Collaborator

@0xyaco 0xyaco commented Aug 16, 2024

🤖 Linear

Closes GRT-27

Description

Implements the EboActorsManager class.

Copy link

linear bot commented Aug 16, 2024

GRT-27 EBOActorsManager

The EboActorsManager is the entity in charge of creating actors and linking those actors to their respective requests. It will be used to route each event to its corresponding actor.

AC:

  • Allow actor creation while linking the actor with the request ID
  • Allow actor lookup by request ID
  • Allow actor removal

Resources

@0xyaco 0xyaco requested review from 0xkenj1 and 0xnigir1 August 16, 2024 19:00
return this.requestActorMap.get(requestId);
}

public deleteActor(requestId: string): boolean {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is returning a boolean ? Should it be void ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

same doubt, i guess on error false is returned instead of throwing

Copy link
Collaborator Author

@0xyaco 0xyaco Aug 16, 2024

Choose a reason for hiding this comment

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

We can do void.

I'm just following the Map.prototype.delete() return type for the sake of consistency.

I guess it doesn't hurt to keep the boolean return type, but now that you mention, I should add some docs on these methods, it would've helped here 😬

Copy link
Collaborator

Choose a reason for hiding this comment

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

yep, would be very helpful for the user of this class, should we add a warn or sth if the requestId doesn't exist?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good. The EboProcessor will most likely warn if the delete returns false when removing actors from the registry; can't think of any situation out of the top of my head where that'd happen, but better to be safe than sorry.

Comment on lines 10 to 13
import { ProtocolProvider } from "../../src/protocolProvider.js";
import { EboEvent } from "../../src/types/events.js";
import { Response } from "../../src/types/prophet.js";
import mocks from "../mocks/index.js";
Copy link
Collaborator

Choose a reason for hiding this comment

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

ensure you are importing from index files

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I need to find a way to have my VSCode stop importing from non-index files lol

Comment on lines 14 to 21
const request = DEFAULT_MOCKED_REQUEST_CREATED_DATA;
const { actor } = mocks.buildEboActor(request, logger);
const actorsManager = new EboActorsManager();
const mockSetRequestActorMap = vi.spyOn(actorsManager["requestActorMap"], "set");

actorsManager.registerActor(request.id, actor);

expect(mockSetRequestActorMap).toHaveBeenCalledWith(request.id, actor);
Copy link
Collaborator

Choose a reason for hiding this comment

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

i would check if map was effectively appended

import { EboActor } from "./eboActor.js";
import { RequestAlreadyHandled } from "./exceptions/index.js";

export class EboActorsManager {
Copy link
Collaborator

Choose a reason for hiding this comment

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

the manager implementation is always in-memory or is like the Registry that may in the future be a Redis or whatever makes sense? in that case, we should have the proper interface

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's something interesting to think about; in this case I think The Graph should need to scale a lot for this to need something outside the in-memory solution used here. Worst case scenario, at the same there will be 1 item (ie 1 <request, actor> tuple) for every indexed chain, which are not that many.

return this.requestActorMap.get(requestId);
}

public deleteActor(requestId: string): boolean {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same doubt, i guess on error false is returned instead of throwing

Base automatically changed from feat/on-finalize-request to dev August 16, 2024 21:25
@0xyaco 0xyaco changed the title Feat/actors manager feat: implement EboActorsManager Aug 16, 2024
@0xyaco
Copy link
Collaborator Author

0xyaco commented Aug 16, 2024

@0xkenj1 @0xnigir1 did a small refactor on EboActorsManager.registerActor as I've realized that with the old signature (ie registerActor(requestId, actor)) we would have to explicitly handle the case when the requestId !== actor.requestId to validate that the link between requestId and actor makes sense, which would've been silly, so... Just passing the actor and reading the requestId out of the actor itself seemed the wisest path. What do you think?

@0xyaco 0xyaco requested review from 0xkenj1 and 0xnigir1 August 19, 2024 12:17
Copy link
Collaborator

@0xnigir1 0xnigir1 left a comment

Choose a reason for hiding this comment

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

lgtmm 🚀

return this.requestActorMap.get(requestId);
}

public deleteActor(requestId: string): boolean {
Copy link
Collaborator

Choose a reason for hiding this comment

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

yep, would be very helpful for the user of this class, should we add a warn or sth if the requestId doesn't exist?

@0xyaco 0xyaco merged commit 5047f01 into dev Aug 20, 2024
5 checks passed
@0xyaco 0xyaco deleted the feat/actors-manager branch August 20, 2024 16:53
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.

3 participants