config.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package workflow
  2. import (
  3. "fmt"
  4. "os"
  5. )
  6. // Config holds workflow engine configuration
  7. type Config struct {
  8. // MaxRetries is the maximum number of retries for a failed node
  9. MaxRetries int
  10. // RetryDelay is the delay between retries in seconds
  11. RetryDelay int
  12. }
  13. // DefaultConfig returns the default workflow configuration
  14. func DefaultConfig() *Config {
  15. return &Config{
  16. MaxRetries: 3,
  17. RetryDelay: 60,
  18. }
  19. }
  20. // LoadConfig loads the workflow configuration from environment variables
  21. func LoadConfig() *Config {
  22. config := DefaultConfig()
  23. // Override with environment variables if set
  24. if maxRetries := os.Getenv("WORKFLOW_MAX_RETRIES"); maxRetries != "" {
  25. config.MaxRetries = parseInt(maxRetries, config.MaxRetries)
  26. }
  27. if retryDelay := os.Getenv("WORKFLOW_RETRY_DELAY"); retryDelay != "" {
  28. config.RetryDelay = parseInt(retryDelay, config.RetryDelay)
  29. }
  30. return config
  31. }
  32. // parseInt parses a string to int, returning default if parsing fails
  33. func parseInt(s string, defaultValue int) int {
  34. var result int
  35. _, err := fmt.Sscanf(s, "%d", &result)
  36. if err != nil {
  37. return defaultValue
  38. }
  39. return result
  40. }