Skip to content

Commit 2e54e9f

Browse files
mfateevmeiliang86
authored andcommitted
Removed default prefix from struct activity names (#92)
1 parent 0022fd9 commit 2e54e9f

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

internal/activity.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ type (
5757

5858
// RegisterActivityOptions consists of options for registering an activity
5959
RegisterActivityOptions struct {
60+
// When an activity is a function the name is an actual activity type name.
61+
// When an activity is part of a structure then each member of the structure becomes an activity with
62+
// this Name as a prefix + activity function name.
6063
Name string
6164
DisableAlreadyRegisteredCheck bool
6265
}

internal/registry.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,7 @@ func (r *registry) registerActivityStruct(aStruct interface{}, options RegisterA
163163
if err := validateFnFormat(method.Type, false); err != nil {
164164
return fmt.Errorf("failed to register activity method %v of %v: %e", name, structType.Name(), err)
165165
}
166-
prefix := options.Name
167-
registerName := name
168-
if len(prefix) == 0 {
169-
prefix = structType.Elem().Name() + "_"
170-
}
171-
registerName = prefix + name
166+
registerName := options.Name + name
172167
if !options.DisableAlreadyRegisteredCheck {
173168
if _, ok := r.getActivityNoLock(registerName); ok {
174169
return fmt.Errorf("activity type \"%v\" is already registered", registerName)

test/workflow_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (w *Workflows) ActivityRetryOnTimeout(ctx workflow.Context, timeoutType sha
109109
ctx = workflow.WithActivityOptions(ctx, opts)
110110

111111
startTime := workflow.Now(ctx)
112-
err := workflow.ExecuteActivity(ctx, "Activities_Sleep", 2*time.Second).Get(ctx, nil)
112+
err := workflow.ExecuteActivity(ctx, "Sleep", 2*time.Second).Get(ctx, nil)
113113
if err == nil {
114114
return nil, fmt.Errorf("expected activity to fail but succeeded")
115115
}
@@ -138,7 +138,7 @@ func (w *Workflows) ActivityRetryOnHBTimeout(ctx workflow.Context) ([]string, er
138138

139139
var result int
140140
startTime := workflow.Now(ctx)
141-
err := workflow.ExecuteActivity(ctx, "Activities_HeartbeatAndSleep", 0, 2*time.Second).Get(ctx, &result)
141+
err := workflow.ExecuteActivity(ctx, "HeartbeatAndSleep", 0, 2*time.Second).Get(ctx, &result)
142142
if err == nil {
143143
return nil, fmt.Errorf("expected activity to fail but succeeded")
144144
}
@@ -453,7 +453,7 @@ func (w *Workflows) RetryTimeoutStableErrorWorkflow(ctx workflow.Context) ([]str
453453
}
454454
ctx = workflow.WithActivityOptions(ctx, ao)
455455

456-
err := workflow.ExecuteActivity(ctx, "Activities_RetryTimeoutStableErrorActivity").Get(ctx, nil)
456+
err := workflow.ExecuteActivity(ctx, "RetryTimeoutStableErrorActivity").Get(ctx, nil)
457457

458458
cerr, ok := err.(*cadence.CustomError)
459459
if !ok {
@@ -487,13 +487,13 @@ func (w *Workflows) childForMemoAndSearchAttr(ctx workflow.Context) (result stri
487487
return
488488
}
489489
ctx = workflow.WithActivityOptions(ctx, w.defaultActivityOptions())
490-
err = workflow.ExecuteActivity(ctx, "Activities_GetMemoAndSearchAttr", memo, searchAttr).Get(ctx, &result)
490+
err = workflow.ExecuteActivity(ctx, "GetMemoAndSearchAttr", memo, searchAttr).Get(ctx, &result)
491491
return
492492
}
493493

494494
func (w *Workflows) sleep(ctx workflow.Context, d time.Duration) error {
495495
ctx = workflow.WithActivityOptions(ctx, w.defaultActivityOptions())
496-
return workflow.ExecuteActivity(ctx, "Activities_Sleep", d).Get(ctx, nil)
496+
return workflow.ExecuteActivity(ctx, "Sleep", d).Get(ctx, nil)
497497
}
498498

499499
func (w *Workflows) InspectActivityInfo(ctx workflow.Context) error {

0 commit comments

Comments
 (0)