-
Notifications
You must be signed in to change notification settings - Fork 198
/
order_activities.go
57 lines (46 loc) · 1.21 KB
/
order_activities.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package choice
import (
"context"
"fmt"
"math/rand"
"go.temporal.io/sdk/activity"
)
type OrderActivities struct {
OrderChoices []string
}
func (a *OrderActivities) GetOrder() (string, error) {
idx := rand.Intn(len(a.OrderChoices))
order := a.OrderChoices[idx]
fmt.Printf("Order is for %s\n", order)
return order, nil
}
func (a *OrderActivities) OrderApple(choice string) error {
fmt.Printf("Order choice: %v\n", choice)
return nil
}
func (a *OrderActivities) OrderBanana(choice string) error {
fmt.Printf("Order choice: %v\n", choice)
return nil
}
func (a *OrderActivities) OrderCherry(choice string) error {
fmt.Printf("Order choice: %v\n", choice)
return nil
}
func (a *OrderActivities) OrderOrange(choice string) error {
fmt.Printf("Order choice: %v\n", choice)
return nil
}
func (a *OrderActivities) GetBasketOrder(ctx context.Context) ([]string, error) {
var basket []string
for _, item := range a.OrderChoices {
// some random decision
if rand.Float32() <= 0.65 {
basket = append(basket, item)
}
}
if len(basket) == 0 {
basket = append(basket, a.OrderChoices[rand.Intn(len(a.OrderChoices))])
}
activity.GetLogger(ctx).Info("Get basket order.", "Orders", basket)
return basket, nil
}