Refactor persistable-task system with self-registering tasks
Replaced metadata-driven reflection with self-describing `PersistableTask` types and a new `PersistableTaskRegistry`. Removed `persistable-tasks.json` and `TaskRegistry`, migrating to type-safe DI instantiation and explicit `restore()` methods. Fixed task restoration issues, ensuring `EmojiReactionRoleTask` and its `emojiMapping` now persist and restore correctly. Introduced `typeId()` for stable task identification, updated payload serialization for symmetry, and applied database migration to map FQCNs to logical IDs. Added unit tests for robust type discovery, payload symmetry, and registry behavior, ensuring no breaking changes.
This commit is contained in:
1 parent
9f2e15a622
commit
05b4a2ab85
19 files changed
+1020
-291
No files matched your search
+10
-5
@@ -2,7 +2,8 @@
|
||||
|
||||
**Packages:** `me.bobert.netneutrality.platform.persistence` (session/migration),
|
||||
`me.bobert.netneutrality.db` (entities, repositories, services).
|
||||
**Resources:** `hibernate.cfg.xml`, `db/migration/V1__initial_schema.sql`.
|
||||
**Resources:** `hibernate.cfg.xml`, `db/migration/V1__initial_schema.sql`,
|
||||
`db/migration/V2__task_type_id.sql`.
|
||||
|
||||
## Stack
|
||||
|
||||
@@ -55,7 +56,7 @@ of a star-shaped model; most other tables reference `guild_id` with `ON DELETE C
|
||||
| `OLogging` | `logging` | `OLoggingId` (composite) | Composite key `guild_id` + `channel_id`; `@MapsId` to `OGuild`; debug/error log channel config. |
|
||||
| `OLoggingId` | — (embeddable) | — | `@Embeddable`/`@IdClass` for the composite key. |
|
||||
| `OLogMessage` | `log_message` | `id` (auto int) | Many-to-one `OGuild`; message logging history. |
|
||||
| `OTask` | `tasks` | `id` (auto int) | [Persistable task](tasks.md#31-persistable-tasks) state; unique `task_id`, class name, JSON `payload`. |
|
||||
| `OTask` | `tasks` | `id` (auto int) | [Persistable task](tasks.md#31-persistable-tasks) state; unique `task_id`, `task_class` holds the logical `typeId`, JSON `payload`. |
|
||||
| `OWebUser` | `web_users` | `id` (String) | Web dashboard user (tokens/expiry). *Present in schema & code but not listed in `hibernate.cfg.xml`.* |
|
||||
|
||||
### ER overview
|
||||
@@ -102,8 +103,9 @@ Services wrap repositories with business logic and **caching**.
|
||||
values in `settingsCache` and reloads on change; used by the
|
||||
[web API settings endpoints](web-api.md).
|
||||
- **`TaskService`** — serializes [`PersistableTask`](tasks.md#31-persistable-tasks) instances to JSON
|
||||
for the `tasks` table and reconstructs them at startup via
|
||||
[`TaskRegistry`/`TaskFactory`](tasks.md#31-persistable-tasks).
|
||||
for the `tasks` table, keyed by the task's stable `typeId()` in `task_class`, and reconstructs them
|
||||
at startup via [`PersistableTaskRegistry`](tasks.md#persistabletaskregistry--discovery-and-restore).
|
||||
Rows with an unknown `task_class` are logged and skipped.
|
||||
|
||||
## GSettings
|
||||
|
||||
@@ -125,4 +127,7 @@ role/channel and how `ConfigureCommand` persists changes.
|
||||
The initial migration creates the tables backing the entities above (`guilds`, `guild_settings`,
|
||||
`blacklist`, `logging`, `log_message`, `tasks`, `web_users`), with `guild_id` foreign keys and
|
||||
`ON DELETE CASCADE` from the guild-scoped tables to `guilds`. Subsequent schema changes should be
|
||||
added as new `V2__…`, `V3__…` Flyway scripts in the same directory.
|
||||
added as new `V3__…`, `V4__…` Flyway scripts in the same directory.
|
||||
|
||||
`V2__task_type_id.sql` rewrites `tasks.task_class` from the old fully-qualified class names to the
|
||||
stable logical `typeId` (e.g. `emoji-reaction-role`), so previously persisted rows remain loadable.
|
||||
Reference in new issue
Block a user