Files
tasks/common/persistence/faultinjection/store_fault_generator.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
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).
2026-03-19 10:36:40 -07:00

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