Last active
August 29, 2015 13:57
-
-
Save zeisss/9766129 to your computer and use it in GitHub Desktop.
Alternative design to specify name/group/... for goHystrix
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
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