-
Notifications
You must be signed in to change notification settings - Fork 1
feat: extract EventStore, Timeline, and DLQ as self-registering modules (#90) #125
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package module | ||
|
|
||
| import ( | ||
| "log/slog" | ||
| "net/http" | ||
|
|
||
| "github.com/CrisisTextLine/modular" | ||
| evstore "github.com/GoCodeAlone/workflow/store" | ||
| ) | ||
|
|
||
| // DLQServiceConfig holds the configuration for the DLQ service module. | ||
| type DLQServiceConfig struct { | ||
| // MaxRetries is reserved for future implementation of per-entry retry limits. | ||
| // It is stored and exposed via MaxRetries() but not yet applied to the DLQ store. | ||
| MaxRetries int `yaml:"max_retries" default:"3"` | ||
| // RetentionDays is reserved for future implementation of automatic DLQ entry purging. | ||
| // It is stored and exposed via RetentionDays() but not yet applied to the DLQ store. | ||
| RetentionDays int `yaml:"retention_days" default:"30"` | ||
| } | ||
|
|
||
| // DLQServiceModule wraps an evstore.DLQHandler as a modular.Module. | ||
| // It initializes the in-memory DLQ store and handler, making them available | ||
| // in the modular service registry. | ||
| type DLQServiceModule struct { | ||
| name string | ||
| config DLQServiceConfig | ||
| store *evstore.InMemoryDLQStore | ||
| handler *evstore.DLQHandler | ||
| mux *http.ServeMux | ||
| } | ||
|
|
||
| // NewDLQServiceModule creates a new DLQ service module with the given name and config. | ||
| func NewDLQServiceModule(name string, cfg DLQServiceConfig) *DLQServiceModule { | ||
| logger := slog.Default() | ||
|
|
||
| dlqStore := evstore.NewInMemoryDLQStore() | ||
| dlqHandler := evstore.NewDLQHandler(dlqStore, logger) | ||
| dlqMux := http.NewServeMux() | ||
| dlqHandler.RegisterRoutes(dlqMux) | ||
|
|
||
| logger.Info("Created DLQ handler", "module", name) | ||
|
|
||
| return &DLQServiceModule{ | ||
| name: name, | ||
| config: cfg, | ||
| store: dlqStore, | ||
| handler: dlqHandler, | ||
| mux: dlqMux, | ||
| } | ||
| } | ||
|
|
||
| // Name implements modular.Module. | ||
| func (m *DLQServiceModule) Name() string { return m.name } | ||
|
|
||
| // Init implements modular.Module. | ||
| func (m *DLQServiceModule) Init(_ modular.Application) error { return nil } | ||
|
|
||
| // ProvidesServices implements modular.Module. The DLQ handler mux is registered | ||
| // under the module name and also under {name}.admin for admin route delegation. | ||
| func (m *DLQServiceModule) ProvidesServices() []modular.ServiceProvider { | ||
| return []modular.ServiceProvider{ | ||
| { | ||
| Name: m.name, | ||
| Description: "DLQ service: " + m.name, | ||
| Instance: m.mux, | ||
| }, | ||
| { | ||
| Name: m.name + ".admin", | ||
| Description: "DLQ admin handler: " + m.name, | ||
| Instance: http.Handler(m.mux), | ||
| }, | ||
| { | ||
| Name: m.name + ".store", | ||
| Description: "DLQ store: " + m.name, | ||
| Instance: m.store, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| // RequiresServices implements modular.Module. | ||
| func (m *DLQServiceModule) RequiresServices() []modular.ServiceDependency { | ||
| return nil | ||
| } | ||
|
|
||
| // DLQMux returns the HTTP mux for DLQ endpoints. | ||
| func (m *DLQServiceModule) DLQMux() http.Handler { return m.mux } | ||
|
|
||
| // Store returns the underlying DLQ store. | ||
| func (m *DLQServiceModule) Store() *evstore.InMemoryDLQStore { return m.store } | ||
|
|
||
| // MaxRetries returns the configured max retry count. | ||
| func (m *DLQServiceModule) MaxRetries() int { return m.config.MaxRetries } | ||
|
|
||
| // RetentionDays returns the configured retention period. | ||
| func (m *DLQServiceModule) RetentionDays() int { return m.config.RetentionDays } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DLQServiceConfig exposes max_retries and retention_days, but the module currently doesn't apply either setting to the DLQ store or handler (NewDLQHandler doesn't accept options and the in-memory store doesn't enforce retention). This makes the config + schema misleading; either implement the behavior (e.g., enforce defaults when creating DLQEntry / schedule purges) or remove these fields from config/schema until supported.