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

Refactor logger to use the actor model #99

Open
wants to merge 5 commits into
base: unstable
Choose a base branch
from

Conversation

OJarrisonn
Copy link
Contributor

This PR is the starting point of the major patch-hub refactor to use the Actor Model. I decided to start it with the logger because it's the most straightforward actor in my design.

What is done?

  • Add actix crate
  • Replaced current logger with an actor

What's not done?

  • Handle .await properly
  • Fix the install_hooks since it doesn't support async move
  • Mocked actor for testing
  • Integration with the config options

The Design

So basically the Logger actor implements the Actor trait and I've created a couple of messages that it can handle:

  • Info, Warn, Error: to log messages
  • InfoOnError, WarnOnError, ErrorOnError: to log results if .is_err()
  • Flush: flushes the messages to the terminal
  • CollectGarbage: removes old log files

Also i used an extension trait pattern (don't know if this is a real name) to simplify the code that uses the actor. Just by implementing extension methods on Addr<Logger> to send the messages directly. Without those methods using the logger is:

// logger: Addr<Logger>
let result: Result<(), MailboxError> = logger.send(logger::Error("Something went wrong")).await;

With this pattern we create a trait LoggerActor and implement it on Addr<Logger> and then simplify the calls to just:

// logger: Addr<Logger> as LoggerActor
let result: Result<(), MailboxError> = logger.error("Something went wrong").await;

Final Considerations

This PR do not break patch-hub in any way, the app is completely functional so it's safe to be merged in that sense

Signed-off-by: OJarrisonn <j.h.m.t.v.10@gmail.com>
Makes the main function async to allow future usage of actors

Signed-off-by: OJarrisonn <j.h.m.t.v.10@gmail.com>
@OJarrisonn OJarrisonn force-pushed the refactor/logger-actor branch from dd5cb80 to 5fdd5c4 Compare February 6, 2025 04:43
Signed-off-by: OJarrisonn <j.h.m.t.v.10@gmail.com>
Signed-off-by: OJarrisonn <j.h.m.t.v.10@gmail.com>
Signed-off-by: OJarrisonn <j.h.m.t.v.10@gmail.com>
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.

2 participants