-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathactivities.go
66 lines (50 loc) · 1.36 KB
/
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
58
59
60
61
62
63
64
65
66
package synchronousproxy
import (
"context"
"fmt"
"time"
"go.temporal.io/sdk/activity"
"go.temporal.io/sdk/temporal"
)
func RegisterEmail(ctx context.Context, email string) error {
logger := activity.GetLogger(ctx)
logger.Info("activity: registered email", email)
return nil
}
func ValidateSize(ctx context.Context, size string) error {
for _, key := range TShirtSizes {
if key == size {
return nil
}
}
return temporal.NewNonRetryableApplicationError(
fmt.Sprintf("size: %s is not valid (%v)", size, TShirtSizes),
"InvalidSize",
nil,
nil,
)
}
func ValidateColor(ctx context.Context, color string) error {
for _, key := range TShirtColors {
if key == color {
return nil
}
}
return temporal.NewNonRetryableApplicationError(
fmt.Sprintf("color: %s is not valid (%v)", color, TShirtColors),
"InvalidColor",
nil,
nil,
)
}
func ScheduleDelivery(ctx context.Context, order TShirtOrder) (time.Time, error) {
logger := activity.GetLogger(ctx)
deliveryDate := time.Now().Add(time.Hour * 48)
logger.Info("activity: scheduled delivery", order, deliveryDate)
return deliveryDate, nil
}
func SendDeliveryEmail(ctx context.Context, order TShirtOrder, deliveryDate time.Time) error {
logger := activity.GetLogger(ctx)
logger.Info(fmt.Sprintf("email to: %s order: %v scheduled delivery: %v", order.Email, order, deliveryDate))
return nil
}