Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active March 2, 2022 06:57
Show Gist options
  • Save percybolmer/439ebdc61ac314b9c24fcba8d60761a6 to your computer and use it in GitHub Desktop.
Save percybolmer/439ebdc61ac314b9c24fcba8d60761a6 to your computer and use it in GitHub Desktop.
The first simple activities to run in a Cadence workflow
// activityGreetings is used to say Hello to a Customer and change their LastVisit and TimesVisisted
// The returned value will be a Customer struct filled with this information
func activityGreetings(ctx context.Context, visitor customer.Customer) (customer.Customer, error) {
logger := activity.GetLogger(ctx)
logger.Info("Greetings activity started")
logger.Info("New Visitor", zap.String("customer", visitor.Name), zap.Int("visitorCount", visitorCount))
visitorCount++
oldCustomerInfo, _ := customer.Database.Get(visitor.Name)
visitor.LastVisit = time.Now()
visitor.TimesVisited = oldCustomerInfo.TimesVisited + 1
return visitor, nil
}
// activityStoreCustomer is used to store the Customer in the configured Customer Storage.
func activityStoreCustomer(ctx context.Context, visitor customer.Customer) error {
logger := activity.GetLogger(ctx)
logger.Info("Store Customer activity started")
logger.Info("Updating Customer", zap.String("customer", visitor.Name), zap.Time("lastVisit", visitor.LastVisit),
zap.Int("timesVisited", visitor.TimesVisited))
// Store Customer in Database (Memory Cache during this Example)
err := customer.Database.Update(visitor)
if err != nil {
return err
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment