Skip to content

Instantly share code, notes, and snippets.

View percybolmer's full-sized avatar

ProgrammingPercy percybolmer

View GitHub Profile
@percybolmer
percybolmer / cadence-first-success.go
Created February 28, 2022 19:39
Cadence first success execution
cadence --domain tavern workflow run --tl greetings --wt programmingpercy/cadence-tavern/workflows/greetings.workflowGreetings --et 60 -i '{"name": "Percy"}'
@percybolmer
percybolmer / cadence-broken-execution.sh
Created February 28, 2022 19:30
Cadence without input
cadence --domain tavern workflow run --tl greetings --wt programmingpercy/cadence-tavern/workflows/greetings.workflowGreetings --et 60
@percybolmer
percybolmer / cadence-failure-to-run.go
Last active February 28, 2022 19:29
Cadence CLI logs when failing to publish job
Running execution:
Workflow Id : 21e30ae8-8246-412d-a6d2-cc0782cf66d4
Run Id : 7c3514b4-6839-43ee-9d45-d9d54c7c9a44
Type : programmingpercy/cadence-tavern/workflows/greetings.workflowGreetings
Domain : tavern
Task List : greetings
Args :
Progress:
1, 2022-02-28T20:27:25+01:00, WorkflowExecutionStarted
2, 2022-02-28T20:27:25+01:00, DecisionTaskScheduled
@percybolmer
percybolmer / cadence-first-worker-execution.go
Created February 28, 2022 19:13
Cadence running the worker service
percy@tavern: go run main.go
2022-02-28T20:12:23.215+0100 INFO internal/internal_worker.go:834 Started Workflow Worker {"Domain": "tavern", "TaskList": "greetings", "WorkerID": "10484@DESKTOP-3DP516F@greetings@b2156771-c3f8-4e3e-845f-375b1f58081a"}
2022-02-28T20:12:23.239+0100 INFO internal/internal_worker.go:859 Started Activity Worker {"Domain": "tavern", "TaskList": "greetings", "WorkerID": "10484@DESKTOP-3DP516F@greetings@b2156771-c3f8-4e3e-845f-375b1f58081a"}
2022-02-28T20:12:23.239+0100 INFO app/main.go:44 Started Worker. {"worker": "greetings"}
@percybolmer
percybolmer / Cadence-service-worker-v2.go
Created February 28, 2022 18:53
Cadence added import
package main
import (
"fmt"
// Here we Import the Package, which will make Register Kick in
_ "programmingpercy/cadence-tavern/workflows/greetings"
_ "go.uber.org/cadence/.gen/go/cadence"
"go.uber.org/cadence/.gen/go/cadence/workflowserviceclient"
"go.uber.org/cadence/worker"
@percybolmer
percybolmer / cadence-greetings-workflow-v1.go
Last active March 2, 2022 06:58
Cadence the first full Complete greetings workflow
package greetings
import (
"context"
"programmingpercy/cadence-tavern/customer"
"time"
"go.uber.org/cadence/activity"
"go.uber.org/cadence/workflow"
"go.uber.org/zap"
@percybolmer
percybolmer / cadence-register-activitesnWorkflows.go
Created February 28, 2022 18:45
Cadence-register workflows and activites
func init() {
// init will be called once the workflow file is imported
// this will Register the workflow to the Worker service
workflow.Register(workflowGreetings)
// Register the activities also
activity.Register(activityGreetings)
activity.Register(activityStoreCustomer)
}
@percybolmer
percybolmer / cadence-first-activities.go
Last active March 2, 2022 06:57
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)
@percybolmer
percybolmer / cadence-firstworkflow.go
Created February 28, 2022 18:36
Cadence workflow for greeting and storing customer information
// workflowGreetings is the Workflow that is used to handle new Customers in the Tavern.
// our Workflow accepts a customer as Input, and Outputs a Customer, and an Error
func workflowGreetings(ctx workflow.Context, visitor customer.Customer) (customer.Customer, error) {
// workflow Options for HeartBeat Timeout and other Timeouts.
ao := workflow.ActivityOptions{
ScheduleToStartTimeout: time.Minute,
StartToCloseTimeout: time.Minute,
HeartbeatTimeout: time.Second * 20,
// Here we will Add Retry policies etc later
}
@percybolmer
percybolmer / cadence-example-workflows.go
Last active February 28, 2022 18:23
candece-workflow examples
// This function is valid, accepts a Customer in JSON format as Input, Outputs a Customer and an error
func workflowGreetings(ctx workflow.Context, visitor customer.Customer) (customer.Customer, error)
// This could be valid, accept No input and Output a Customer and Error.
func workflowGreetings(ctx workflow.Context) (customer.Customer, error)
// Accept string as input, output only an Error
func workflowGreetings(ctx workflow.Context, input string) error