-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(sagas): prettify sagas config (#116)
* fix: unified provideConfig * fix: make sagas config more pretty
- Loading branch information
Showing
16 changed files
with
197 additions
and
95 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,51 @@ | ||
package sagas | ||
|
||
import ( | ||
"github.com/DoNewsCode/core/config" | ||
"github.com/DoNewsCode/core/di" | ||
"time" | ||
) | ||
|
||
type configOut struct { | ||
di.Out | ||
|
||
Config []config.ExportedConfig `group:"config,flatten"` | ||
} | ||
|
||
var defaultConfig = configuration{ | ||
SagaTimeout: config.Duration{Duration: 600 * time.Second}, | ||
RecoverInterval: config.Duration{Duration: 60 * time.Second}, | ||
} | ||
|
||
func provideConfig() configOut { | ||
return configOut{ | ||
Config: []config.ExportedConfig{ | ||
{ | ||
Owner: "sagas", | ||
Data: map[string]interface{}{ | ||
"sagas": defaultConfig, | ||
}, | ||
Comment: "The saga configuration.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
type configuration struct { | ||
SagaTimeout config.Duration `json:"sagaTimeout" yaml:"sagaTimeout"` | ||
RecoverInterval config.Duration `json:"recoverInterval" yaml:"recoverInterval"` | ||
} | ||
|
||
func (c configuration) getSagaTimeout() config.Duration { | ||
if !c.SagaTimeout.Valid() { | ||
return defaultConfig.SagaTimeout | ||
} | ||
return c.SagaTimeout | ||
} | ||
|
||
func (c configuration) getRecoverInterval() config.Duration { | ||
if !c.RecoverInterval.Valid() { | ||
return defaultConfig.RecoverInterval | ||
} | ||
return c.RecoverInterval | ||
} |
This file contains 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 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 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,60 @@ | ||
package mysqlstore | ||
|
||
import ( | ||
"github.com/DoNewsCode/core/config" | ||
"github.com/DoNewsCode/core/di" | ||
"time" | ||
) | ||
|
||
type configOut struct { | ||
di.Out | ||
|
||
Config []config.ExportedConfig `group:"config,flatten"` | ||
} | ||
|
||
var defaultConfig = configuration{ | ||
Connection: "default", | ||
Retention: config.Duration{Duration: 168 * time.Hour}, | ||
CleanupInterval: config.Duration{Duration: time.Hour}, | ||
} | ||
|
||
func provideConfig() configOut { | ||
return configOut{ | ||
Config: []config.ExportedConfig{ | ||
{ | ||
Owner: "sagas", | ||
Data: map[string]interface{}{ | ||
"sagas-mysql": defaultConfig, | ||
}, | ||
Comment: "The saga mysql store configuration.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
type configuration struct { | ||
Connection string `json:"connection" yaml:"connection"` | ||
Retention config.Duration `json:"retention" yaml:"retention"` | ||
CleanupInterval config.Duration `json:"cleanupInterval" yaml:"cleanupInterval"` | ||
} | ||
|
||
func (c configuration) getConnection() string { | ||
if c.Connection == "" { | ||
return defaultConfig.Connection | ||
} | ||
return c.Connection | ||
} | ||
|
||
func (c configuration) getRetention() config.Duration { | ||
if !c.Retention.Valid() { | ||
return defaultConfig.Retention | ||
} | ||
return c.Retention | ||
} | ||
|
||
func (c configuration) getCleanupInterval() config.Duration { | ||
if !c.CleanupInterval.Valid() { | ||
return defaultConfig.CleanupInterval | ||
} | ||
return c.CleanupInterval | ||
} |
This file contains 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 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 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 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
Oops, something went wrong.