Skip to content

Conversation

@Kitt3120
Copy link
Contributor

@Kitt3120 Kitt3120 commented Oct 4, 2024

Ignore this

* Implement config

 - Add dirs crate
 - Implement ConfigHandler
 - Implement custom error types
 - Implement config struct
 - Load config on startup

* Use thiserror

 - Add thiserror crate
 - Refactor existing error types to use thiserror
Update README.md

Add reference to Milestones page
* Add portrait image

* Add portrait image to README.md
* Implement service framework

 - Make main async
 - Implement Status enum
 - Implement Priority enum
 - Implement ServiceInfo struct
 - Implement ServiceInternals trait
 - Implement Service trait

* Bot library

 - Add fern crate
 - Add humantime crate
 - Add log crate
 - Implement Bot
 - Implement BotBuilder
 - Refactor config Display trait implementation
 - Implement library is_debug() function
 - Implement library run(Bot) function
 - Implement log module (log::setup(), log::is_set_up() and log::get_min_log_level())
 - Adapt main to new changes

* WIP: Finish services framework

Just a lot of refactoring and fixing. No time to describe all this now. Happy new year! :)

* Finish services framework

Too much to describe. It's done, that's it. This was one hell of a ride.
- Refined some derived traits
 - Refactor Service/ServiceInfo: Move some trait implementations from Service to ServiceInfo and refer to the implementations from Service
 - Compare ID instead of name in ServiceManagerBuilder
* Add serenity

Add serenity as a dependency and use some extra features and the native TLS backend

* Implement Discord Service

 - Implement Discord Service
 - Add discordTimeout config variable
 - Add additional logger setup to mute unimportant messages introduced by serenity
* Service framework improvements

 - Way better handling of mutable/immutable attributes
 - Less Mutexes
 - Better handling of passing references through the service framework's API
 - Reimplement get_service accepting a TypeId as a generic parameter for easier usage
 - Reimplement status_map and status_tree as a result of the above adaptations, resulting in way simpler versions

* More service framework improvements

 - Replace all Mutexes with RwLock
 - Remove status_map method of ServiceManager
 - Services vector in ServiceManager now wraps the Service trait objects in a RwLock to potentially make them available mutably through the public API of ServiceManager

* Implement get_service<T> method

 - Add downcast-rs crate
 - Implement get_service<T> method of ServiceManager

Had to use unsafe Rust for this. Tried it with safe Rust for 3 days and couldn't do it. With unsafe Rust, it's very easy. It's also still kinda safe, as the crash case is checked and prevented before going into the unsafe block.

* Finish refactor of service framework

 - ServiceManager now holds an Arc to itself
 - Self-Arc is now passed to services when initializing them, so they can access other services and copy Arcs to those for themselves
 - Implement SetLock<T> struct which is a wrapper around Option<T> for lazy-initialization
 - ServiceManagerBuilder handles the creation and injection of the Self-Arc of ServiceManager. That's why the build() method is now async and the From trait had to be removed. The From trait cannot be implemented async.
 - To keep everything consistent, the From trait has also been removed from the BotBuilder and the build() method becase async.

* Adapt Discord service

 - Adapt Discord service to new service framework and SetLock type
 - Fix deadlock when accessing the ServiceManager parameter in start() method of a Service
 - Known bug: Deadlock still happens when a service accesses itself through the ServiceManager on start
Refactor service

start_wrapped and stop_wrapped have been removed from the Service trait and the logic has been implemented in the Service Manager.
- Add hardcoded timeout of 10 seconds on service startup
 - Add hardcoded timeout of 10 seconds on service shutdown
 - Remove timeout implementation of Discord service, as it is now handled by the Service Manager.
* Service framework background task

 - Implement an optional background task for services that starts automatically on service start.
 - Implement a watchdog that updates the service's status when its task fails at runtime

* WIP: Partially implemented

 - Background task startup + watchdog implemented for service startup
 - Implementation for service shutdown missing
 - Handling of watchdog triggers of essential tasks missing

* Refactor of service framework

Split service framework into multiple submodules

* Implement Watchdog module

* Optimize Watchdog module

Make usage of Watchdog more flexible

* Refactor start_service

Refactor the giant block of cod e into smaller helper methods where possible

* Edit StartupError string representations

* Finish refactor of start_service method

* Refactor stop_service

 - Apply same refactoring to stop_service
 - Increase name placeholder space to 30 in logger
 - Made Status clonable by not using BoxedErrors anymore but Strings for holding the error information
 - Add get_status() to Service
 - Made status property of Service private
 - Implement Event<T>
 - Add status_changed Event to ServiceInfo
 - Add name attribute to Event<T>
 - Unify Channel and Closure subscribers by using an Enum
 - Propagate errors when dispatching events
 - Add error log when errors occur while dispatching events
 - Subscribers are now removed from an event when they run into an error while dispatching
Make the removal of Event subscribers on error optional
 - Refactors in service_manager.rs
 - Refactors in watchdog.rs
I made these changes many months ago. Reviewed them for like half an hour, looks good. I know what I was working on. Will continue now :)
@Kitt3120 Kitt3120 added the feature Adds or requests new feature label Oct 4, 2024
@Kitt3120 Kitt3120 added this to the MVP milestone Oct 4, 2024
@Kitt3120 Kitt3120 self-assigned this Oct 4, 2024
@Kitt3120 Kitt3120 merged commit 0f51e3d into main Oct 4, 2024
7 checks passed
@Kitt3120 Kitt3120 deleted the feature/service-status-events branch October 4, 2024 14:33
@Kitt3120 Kitt3120 removed this from the MVP milestone Oct 4, 2024
@Kitt3120 Kitt3120 linked an issue Oct 4, 2024 that may be closed by this pull request
@Kitt3120 Kitt3120 restored the feature/service-status-events branch October 4, 2024 14:41
@Kitt3120 Kitt3120 changed the title Merge feature/service-status-events into main <IGNORE> Merge feature/service-status-events into main Oct 4, 2024
@Kitt3120 Kitt3120 removed their assignment Oct 4, 2024
@Kitt3120 Kitt3120 removed the feature Adds or requests new feature label Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants