mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
Full module path rebrand from Temporal to Hanzo Tasks: - go.mod module: github.com/hanzoai/tasks - All internal Go imports updated (1906 files) - cmd/server renamed to cmd/tasksd - Binary name: tasksd (was temporal-server) - Docker images: hanzoai/tasks (was temporalio/server) - README rewritten with Hanzo Tasks branding - LLM.md created with integration notes - Makefile, goreleaser, CI workflows updated - go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos) Fork of Temporal.io (MIT license).
42 lines
1.6 KiB
Go
42 lines
1.6 KiB
Go
package faultinjection
|
|
|
|
import (
|
|
"github.com/hanzoai/tasks/common/config"
|
|
)
|
|
|
|
type (
|
|
// storeFaultGenerator is an implementation of faultGenerator that will inject errors into the persistence layer
|
|
// using a per-method configuration.
|
|
storeFaultGenerator struct {
|
|
methodFaultGenerators map[string]faultGenerator
|
|
}
|
|
)
|
|
|
|
// newStoreFaultGenerator returns a new instance of a data store error generator that will inject errors
|
|
// into the persistence layer based on the provided configuration.
|
|
func newStoreFaultGenerator(cfg *config.FaultInjectionDataStoreConfig) *storeFaultGenerator {
|
|
methodFaultGenerators := make(map[string]faultGenerator, len(cfg.Methods))
|
|
for methodName, methodConfig := range cfg.Methods {
|
|
var faults []fault
|
|
for errName, errRate := range methodConfig.Errors {
|
|
faults = append(faults, newFault(errName, errRate, methodName))
|
|
}
|
|
methodFaultGenerators[methodName] = newMethodFaultGenerator(faults, methodConfig.Seed)
|
|
}
|
|
return &storeFaultGenerator{
|
|
methodFaultGenerators: methodFaultGenerators,
|
|
}
|
|
}
|
|
|
|
// Generate returns an error from the configured error types and rates for this method.
|
|
// If no errors are configured for the method, or if there are some errors configured for this method,
|
|
// but no error is sampled, then this method returns nil.
|
|
// When this method returns nil, this causes the persistence layer to use the real implementation.
|
|
func (d *storeFaultGenerator) generate(methodName string) *fault {
|
|
methodGenerator, ok := d.methodFaultGenerators[methodName]
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return methodGenerator.generate(methodName)
|
|
}
|