Refactor logger
to use the actor model
#99
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?
actix
crateWhat's not done?
.await
properlyinstall_hooks
since it doesn't supportasync move
The Design
So basically the
Logger
actor implements theActor
trait and I've created a couple of messages that it can handle:Info
,Warn
,Error
: to log messagesInfoOnError
,WarnOnError
,ErrorOnError
: to log results if.is_err()
Flush
: flushes the messages to the terminalCollectGarbage
: removes old log filesAlso 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:With this pattern we create a trait
LoggerActor
and implement it onAddr<Logger>
and then simplify the calls to just: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