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

Implement service startup/shutdown timeout #33

Merged
merged 1 commit into from
Jan 11, 2024

Conversation

Kitt3120
Copy link
Owner

  • 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.

 - 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.
@Kitt3120 Kitt3120 added the feature Adds or requests new feature label Jan 11, 2024
@Kitt3120 Kitt3120 self-assigned this Jan 11, 2024
@Kitt3120 Kitt3120 linked an issue Jan 11, 2024 that may be closed by this pull request
@Kitt3120 Kitt3120 merged commit 1fe0dbf into staging Jan 11, 2024
6 checks passed
@Kitt3120 Kitt3120 deleted the feature/service-framework-timeout branch January 11, 2024 19:30
Kitt3120 added a commit that referenced this pull request Oct 4, 2024
- 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.
Kitt3120 added a commit that referenced this pull request Oct 4, 2024
* Add config file (#14)

* 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

* Reference Milestones in README.md (#15)

Update README.md

Add reference to Milestones page

* Add README.md portrait (#16)

* Add portrait image

* Add portrait image to README.md

* Add Service Framework (#21)

* 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.

* Refactor codebase (#23)

- 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

* Feature/discord service (#24)

* 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

* Refactor service framework (#25)

* 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 service framework (#31)

 - 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-framework: start_wrapped and stop_wrapped (#32)

Refactor service

start_wrapped and stop_wrapped have been removed from the Service trait and the logic has been implemented in the Service Manager.

* Implement service startup/shutdown timeout (#33)

- 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 tasks and watchdogs (#39)

* 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

* Clonable Status

 - 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

* Adapt Service Manager to new Status enum

* Events

 - Implement Event<T>
 - Add status_changed Event to ServiceInfo

* Event improvements

 - 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

* Event improvements

Make the removal of Event subscribers on error optional

* Slight refactors

 - Refactors in service_manager.rs
 - Refactors in watchdog.rs

* WIP: Idk lol

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 :)

* add: allow clippy::multiple_bound_locations for service module

* add: observables

* refactor: use Mutex instead of RwLock everywhere

* refactor: make remove_on_error work on per-subscriber basis

* refactor: make subscribers identifiable

* refactor: move dispatch logic to Subscriber

* add: AsyncClosure Callback type

* WIP: EventRepeater

* add: EventRepeater

* refactor: event subscribe method names

* refactor: move subscription into own module

* add: AsRef<Event<T>>

* add: UUID, PartialEq/Eq, unsubscribe()

* add: event_repeater detach(), close()

* add: attach/deattach EventRepeater on start/stop of service

* add: service runtime failure handling
Kitt3120 added a commit that referenced this pull request Oct 4, 2024
- 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.
Kitt3120 added a commit that referenced this pull request Oct 4, 2024
* Setup (#1)

- Add tokio, serde and sqlx crates
 - Setup .gitignore
 - Setup Cargo.toml
 - Setup pipelines

* Add config file (#14)

* 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

* Reference Milestones in README.md (#15)

Update README.md

Add reference to Milestones page

* Add README.md portrait (#16)

* Add portrait image

* Add portrait image to README.md

* Add Service Framework (#21)

* 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.

* Refactor codebase (#23)

- 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

* Feature/discord service (#24)

* 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

* Refactor service framework (#25)

* 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 service framework (#31)

 - 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-framework: start_wrapped and stop_wrapped (#32)

Refactor service

start_wrapped and stop_wrapped have been removed from the Service trait and the logic has been implemented in the Service Manager.

* Implement service startup/shutdown timeout (#33)

- 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 tasks and watchdogs (#39)

* 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

* Add Devcontainer (#40)

* added devcontainer

added postgresql and some nice to have extensions

* removed clang to fix pipelines

* Update .devcontainer/devcontainer.json

Co-authored-by: Torben Schweren <[email protected]>

* Update .devcontainer/docker-compose.yml

Co-authored-by: Torben Schweren <[email protected]>

---------

Co-authored-by: Torben Schweren <[email protected]>

* Update sqlx requirement from 0.7.3 to 0.8.0 (#49)

* Bump main to staging (#7)

* Setup (#1)

 - Add tokio, serde and sqlx crates
 - Setup .gitignore
 - Setup Cargo.toml
 - Setup pipelines

* Enable Dependabot (#3)

Add dependabot.yml with daily cargo updates configured

* Fix staging pipelines (#4)

Fix staging pipelines not triggering on pull request

* Implement Cargo caching (#5)

Add Swatinem's Rust-Cache@v2 action to build, test and deploy pipelines

* Improve README.md (#6)

 - Add deployment badges
 - Add collaborating info (board + issues)

* Update sqlx requirement from 0.7.3 to 0.8.0

Updates the requirements on [sqlx](https://github.com/launchbadge/sqlx) to permit the latest version.
- [Changelog](https://github.com/launchbadge/sqlx/blob/main/CHANGELOG.md)
- [Commits](launchbadge/sqlx@v0.7.3...v0.8.0)

---
updated-dependencies:
- dependency-name: sqlx
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

* remove: empty line

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Torben Schweren <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Merge feature/service-status-events into staging (#55)

* Bump main to staging (#7)

* Setup (#1)

 - Add tokio, serde and sqlx crates
 - Setup .gitignore
 - Setup Cargo.toml
 - Setup pipelines

* Enable Dependabot (#3)

Add dependabot.yml with daily cargo updates configured

* Fix staging pipelines (#4)

Fix staging pipelines not triggering on pull request

* Implement Cargo caching (#5)

Add Swatinem's Rust-Cache@v2 action to build, test and deploy pipelines

* Improve README.md (#6)

 - Add deployment badges
 - Add collaborating info (board + issues)

* Clonable Status

 - 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

* Adapt Service Manager to new Status enum

* Events

 - Implement Event<T>
 - Add status_changed Event to ServiceInfo

* Event improvements

 - 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

* Event improvements

Make the removal of Event subscribers on error optional

* Slight refactors

 - Refactors in service_manager.rs
 - Refactors in watchdog.rs

* WIP: Idk lol

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 :)

* add: allow clippy::multiple_bound_locations for service module

* add: observables

* refactor: use Mutex instead of RwLock everywhere

* refactor: make remove_on_error work on per-subscriber basis

* refactor: make subscribers identifiable

* refactor: move dispatch logic to Subscriber

* add: AsyncClosure Callback type

* WIP: EventRepeater

* add: EventRepeater

* refactor: event subscribe method names

* refactor: move subscription into own module

* add: AsRef<Event<T>>

* add: UUID, PartialEq/Eq, unsubscribe()

* add: event_repeater detach(), close()

* add: attach/deattach EventRepeater on start/stop of service

* add: service runtime failure handling

* fix: bump version to 0.2.1

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Marco Murawski <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Adds or requests new feature
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Service framework timeout
1 participant