Skip to content

Instantly share code, notes, and snippets.

@zeisss
Last active August 29, 2015 13:57
Show Gist options
  • Save zeisss/9766129 to your computer and use it in GitHub Desktop.
Save zeisss/9766129 to your computer and use it in GitHub Desktop.
Alternative design to specify name/group/... for goHystrix
package main
import (
"fmt"
goHystrix "github.com/ZeissS/goHystrix"
)
type DeleteTransactionCommand struct {
TransactionId string
}
func (cmd *DeleteTransactionCommand) Describe() goHystrix.CommandOptions {
return goHystrix.NewOptions().
WithGroup("payment").
WithName("delete-transaction").
WithIsolation(goHystrix.THREADPOOL_ISOLATION)
WithThreadPool("payment:backend").
WithThreadPoolOptions(goHystrix.ThreadPoolOptions{MaximumOpenOperations: 10})
// WithIsolation(goHystrix.SEMAPHORE_ISOLATION).
// WithSemaphore("payment:cache").
// WithSemaphoreOptions(goHystrix.SemaphoreOptions{MaxmimumOpenOperations: 2})
}
func (cmd *DeleteTransactionCommand) Run() (inteface{}, error) {
return nil, fmt.Errorf("Backend error")
}
func (cmd *DeleteTransactionCommand) Fallback() (inteface{}, error) {
// If an error occured, we just say we failed
return false, nil
}
func main() {
cmd := goHystrix.NewCommand(DeleteTransactionCommand{"123"})
value, err := cmd.Execute()
fmt.Printf("# Results")
fmt.Printf("%v %v\n", value, err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment