Skip to content

Commit 9bcc1a9

Browse files
authoredAug 22, 2024··
Minor docstring grammar updates in activity.go (#1608)
* some docstring updates * minor fix
1 parent a31f86d commit 9bcc1a9

File tree

2 files changed

+60
-62
lines changed

2 files changed

+60
-62
lines changed
 

Diff for: ‎activity/activity.go

+21-22
Original file line numberDiff line numberDiff line change
@@ -39,37 +39,37 @@ type (
3939
// Info contains information about a currently executing activity.
4040
Info = internal.ActivityInfo
4141

42-
// RegisterOptions consists of options for registering an activity
42+
// RegisterOptions consists of options for registering an activity.
4343
RegisterOptions = internal.RegisterActivityOptions
4444
)
4545

46-
// ErrResultPending is returned from activity's implementation to indicate the activity is not completed when
46+
// ErrResultPending is returned from activity's implementation to indicate the activity is not completed when the
4747
// activity method returns. Activity needs to be completed by Client.CompleteActivity() separately. For example, if an
48-
// activity require human interaction (like approve an expense report), the activity could return ErrResultPending
49-
// which indicate the activity is not done yet. Then, when the waited human action happened, it needs to trigger something
50-
// that could report the activity completed event to temporal server via Client.CompleteActivity() API.
48+
// activity requires human interaction (like approving an expense report), the activity could return ErrResultPending,
49+
// which indicates the activity is not done yet. Then, when the waited human action happened, it needs to trigger something
50+
// that could report the activity completed event to the temporal server via the Client.CompleteActivity() API.
5151
var ErrResultPending = internal.ErrActivityResultPending
5252

53-
// GetInfo returns information about currently executing activity.
53+
// GetInfo returns information about the currently executing activity.
5454
func GetInfo(ctx context.Context) Info {
5555
return internal.GetActivityInfo(ctx)
5656
}
5757

58-
// GetLogger returns a logger that can be used in activity
58+
// GetLogger returns a logger that can be used in the activity.
5959
func GetLogger(ctx context.Context) log.Logger {
6060
return internal.GetActivityLogger(ctx)
6161
}
6262

63-
// GetMetricsHandler returns a metrics handler that can be used in activity
63+
// GetMetricsHandler returns a metrics handler that can be used in the activity.
6464
func GetMetricsHandler(ctx context.Context) metrics.Handler {
6565
return internal.GetActivityMetricsHandler(ctx)
6666
}
6767

68-
// RecordHeartbeat sends heartbeat for the currently executing activity
69-
// If the activity is either canceled (or) workflow/activity doesn't exist then we would cancel
68+
// RecordHeartbeat sends a heartbeat for the currently executing activity.
69+
// If the activity is either canceled or the workflow/activity doesn't exist, then we would cancel
7070
// the context with error context.Canceled.
7171
//
72-
// details - the details that you provided here can be seen in the workflow when it receives TimeoutError, you
72+
// details - The details that you provide here can be seen in the workflow when it receives TimeoutError. You
7373
// can check error with TimeoutType()/Details().
7474
//
7575
// Note: If using asynchronous activity completion,
@@ -78,34 +78,33 @@ func RecordHeartbeat(ctx context.Context, details ...interface{}) {
7878
internal.RecordActivityHeartbeat(ctx, details...)
7979
}
8080

81-
// HasHeartbeatDetails checks if there is heartbeat details from last attempt.
81+
// HasHeartbeatDetails checks if there are heartbeat details from the last attempt.
8282
func HasHeartbeatDetails(ctx context.Context) bool {
8383
return internal.HasHeartbeatDetails(ctx)
8484
}
8585

86-
// GetHeartbeatDetails extract heartbeat details from last failed attempt. This is used in combination with retry policy.
87-
// An activity could be scheduled with an optional retry policy on ActivityOptions. If the activity failed then server
88-
// would attempt to dispatch another activity task to retry according to the retry policy. If there was heartbeat
86+
// GetHeartbeatDetails extracts heartbeat details from the last failed attempt. This is used in combination with the retry policy.
87+
// An activity could be scheduled with an optional retry policy on ActivityOptions. If the activity failed, then server
88+
// would attempt to dispatch another activity task to retry according to the retry policy. If there were heartbeat
8989
// details reported by activity from the failed attempt, the details would be delivered along with the activity task for
90-
// retry attempt. Activity could extract the details by GetHeartbeatDetails() and resume from the progress.
90+
// the retry attempt. An activity can extract the details from GetHeartbeatDetails() and resume progress from there.
9191
// See TestActivityEnvironment.SetHeartbeatDetails() for unit test support.
9292
//
93-
// Note, values should not be reused for extraction here because merging on top
94-
// of existing values may result in unexpected behavior similar to
95-
// json.Unmarshal.
93+
// Note: Values should not be reused for extraction here because merging on top
94+
// of existing values may result in unexpected behavior similar to json.Unmarshal.
9695
func GetHeartbeatDetails(ctx context.Context, d ...interface{}) error {
9796
return internal.GetHeartbeatDetails(ctx, d...)
9897
}
9998

10099
// GetWorkerStopChannel returns a read-only channel. The closure of this channel indicates the activity worker is stopping.
101100
// When the worker is stopping, it will close this channel and wait until the worker stop timeout finishes. After the timeout
102-
// hit, the worker will cancel the activity context and then exit. The timeout can be defined by worker option: WorkerStopTimeout.
103-
// Use this channel to handle activity graceful exit when the activity worker stops.
101+
// hits, the worker will cancel the activity context and then exit. The timeout can be defined by worker option: WorkerStopTimeout.
102+
// Use this channel to handle a graceful activity exit when the activity worker stops.
104103
func GetWorkerStopChannel(ctx context.Context) <-chan struct{} {
105104
return internal.GetWorkerStopChannel(ctx)
106105
}
107106

108-
// IsActivity check if the context is an activity context from a normal or local activity.
107+
// IsActivity checks if the context is an activity context from a normal or local activity.
109108
func IsActivity(ctx context.Context) bool {
110109
return internal.IsActivity(ctx)
111110
}

Diff for: ‎internal/activity.go

+39-40
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ import (
3838
)
3939

4040
type (
41-
// ActivityType identifies a activity type.
41+
// ActivityType identifies an activity type.
4242
ActivityType struct {
4343
Name string
4444
}
4545

46-
// ActivityInfo contains information about currently executing activity.
46+
// ActivityInfo contains information about a currently executing activity.
4747
ActivityInfo struct {
4848
TaskToken []byte
4949
WorkflowType *WorkflowType
@@ -60,7 +60,7 @@ type (
6060
IsLocalActivity bool // true if it is a local activity
6161
}
6262

63-
// RegisterActivityOptions consists of options for registering an activity
63+
// RegisterActivityOptions consists of options for registering an activity.
6464
RegisterActivityOptions struct {
6565
// When an activity is a function the name is an actual activity type name.
6666
// When an activity is part of a structure then each member of the structure becomes an activity with
@@ -82,22 +82,22 @@ type (
8282
// The current timeout resolution implementation is in seconds and uses math.Ceil(d.Seconds()) as the duration. But is
8383
// subjected to change in the future.
8484
ActivityOptions struct {
85-
// TaskQueue that the activity needs to be scheduled on.
86-
// optional: The default task queue with the same name as the workflow task queue.
85+
// TaskQueue - Name of the task queue that the activity needs to be scheduled on.
86+
// Optional: The default task queue with the same name as the workflow task queue.
8787
TaskQueue string
8888

89-
// ScheduleToCloseTimeout - Total time that a workflow is willing to wait for Activity to complete.
89+
// ScheduleToCloseTimeout - Total time that a workflow is willing to wait for an Activity to complete.
9090
// ScheduleToCloseTimeout limits the total time of an Activity's execution including retries
9191
// (use StartToCloseTimeout to limit the time of a single attempt).
9292
// The zero value of this uses default value.
93-
// Either this option or StartToClose is required: Defaults to unlimited.
93+
// Either this option or StartToCloseTimeout is required: Defaults to unlimited.
9494
ScheduleToCloseTimeout time.Duration
9595

9696
// ScheduleToStartTimeout - Time that the Activity Task can stay in the Task Queue before it is picked up by
9797
// a Worker. Do not specify this timeout unless using host specific Task Queues for Activity Tasks are being
98-
// used for routing. In almost all situations that don't involve routing activities to specific hosts it is
98+
// used for routing. In almost all situations that don't involve routing activities to specific hosts, it is
9999
// better to rely on the default value.
100-
// ScheduleToStartTimeout is always non-retryable. Retrying after this timeout doesn't make sense as it would
100+
// ScheduleToStartTimeout is always non-retryable. Retrying after this timeout doesn't make sense, as it would
101101
// just put the Activity Task back into the same Task Queue.
102102
// Optional: Defaults to unlimited.
103103
ScheduleToStartTimeout time.Duration
@@ -107,7 +107,7 @@ type (
107107
// to detect that an Activity that didn't complete on time. So this timeout should be as short as the longest
108108
// possible execution of the Activity body. Potentially long running Activities must specify HeartbeatTimeout
109109
// and call Activity.RecordHeartbeat(ctx, "my-heartbeat") periodically for timely failure detection.
110-
// Either this option or ScheduleToClose is required: Defaults to the ScheduleToCloseTimeout value.
110+
// Either this option or ScheduleToCloseTimeout is required: Defaults to the ScheduleToCloseTimeout value.
111111
StartToCloseTimeout time.Duration
112112

113113
// HeartbeatTimeout - Heartbeat interval. Activity must call Activity.RecordHeartbeat(ctx, "my-heartbeat")
@@ -120,112 +120,111 @@ type (
120120
WaitForCancellation bool
121121

122122
// ActivityID - Business level activity ID, this is not needed for most of the cases if you have
123-
// to specify this then talk to temporal team. This is something will be done in future.
123+
// to specify this then talk to the temporal team. This is something will be done in the future.
124124
// Optional: default empty string
125125
ActivityID string
126126

127-
// RetryPolicy specifies how to retry an Activity if an error occurs.
127+
// RetryPolicy - Specifies how to retry an Activity if an error occurs.
128128
// More details are available at docs.temporal.io.
129-
// RetryPolicy is optional. If one is not specified a default RetryPolicy is provided by the server.
129+
// RetryPolicy is optional. If one is not specified, a default RetryPolicy is provided by the server.
130130
// The default RetryPolicy provided by the server specifies:
131131
// - InitialInterval of 1 second
132132
// - BackoffCoefficient of 2.0
133133
// - MaximumInterval of 100 x InitialInterval
134134
// - MaximumAttempts of 0 (unlimited)
135-
// To disable retries set MaximumAttempts to 1.
135+
// To disable retries, set MaximumAttempts to 1.
136136
// The default RetryPolicy provided by the server can be overridden by the dynamic config.
137137
RetryPolicy *RetryPolicy
138138

139-
// If true, will not request eager execution regardless of worker settings.
139+
// If true, eager execution will not be requested, regardless of worker settings.
140140
// If false, eager execution may still be disabled at the worker level or
141-
// eager execution may not be requested due to lack of available slots.
141+
// may not be requested due to lack of available slots.
142142
//
143143
// Eager activity execution means the server returns requested eager
144-
// activities directly from the workflow task back to this worker which is
145-
// faster than non-eager which may be dispatched to a separate worker.
144+
// activities directly from the workflow task back to this worker. This is
145+
// faster than non-eager, which may be dispatched to a separate worker.
146146
DisableEagerExecution bool
147147

148-
// VersioningIntent specifies whether this activity should run on a worker with a compatible
148+
// VersioningIntent - Specifies whether this activity should run on a worker with a compatible
149149
// build ID or not. See temporal.VersioningIntent.
150150
// WARNING: Worker versioning is currently experimental
151151
VersioningIntent VersioningIntent
152152
}
153153

154154
// LocalActivityOptions stores local activity specific parameters that will be stored inside of a context.
155155
LocalActivityOptions struct {
156-
// ScheduleToCloseTimeout - The end to end timeout for the local activity including retries.
156+
// ScheduleToCloseTimeout - The end to end timeout for the local activity, including retries.
157157
// At least one of ScheduleToCloseTimeout or StartToCloseTimeout is required.
158-
// defaults to StartToCloseTimeout if not set.
158+
// Defaults to StartToCloseTimeout if not set.
159159
ScheduleToCloseTimeout time.Duration
160160

161161
// StartToCloseTimeout - The timeout for a single execution of the local activity.
162162
// At least one of ScheduleToCloseTimeout or StartToCloseTimeout is required.
163-
// defaults to ScheduleToCloseTimeout if not set.
163+
// Defaults to ScheduleToCloseTimeout if not set.
164164
StartToCloseTimeout time.Duration
165165

166-
// RetryPolicy specify how to retry activity if error happens.
166+
// RetryPolicy - Specify how to retry activity if error happens.
167167
// Optional: default is to retry according to the default retry policy up to ScheduleToCloseTimeout
168168
// with 1sec initial delay between retries and 2x backoff.
169169
RetryPolicy *RetryPolicy
170170
}
171171
)
172172

173-
// GetActivityInfo returns information about currently executing activity.
173+
// GetActivityInfo returns information about the currently executing activity.
174174
func GetActivityInfo(ctx context.Context) ActivityInfo {
175175
return getActivityOutboundInterceptor(ctx).GetInfo(ctx)
176176
}
177177

178-
// HasHeartbeatDetails checks if there is heartbeat details from last attempt.
178+
// HasHeartbeatDetails checks if there are heartbeat details from last attempt.
179179
func HasHeartbeatDetails(ctx context.Context) bool {
180180
return getActivityOutboundInterceptor(ctx).HasHeartbeatDetails(ctx)
181181
}
182182

183-
// IsActivity check if the context is an activity context from a normal or local activity.
183+
// IsActivity checks if the context is an activity context from a normal or local activity.
184184
func IsActivity(ctx context.Context) bool {
185185
a := ctx.Value(activityInterceptorContextKey)
186186
return a != nil
187187
}
188188

189-
// GetHeartbeatDetails extract heartbeat details from last failed attempt. This is used in combination with retry policy.
190-
// An activity could be scheduled with an optional retry policy on ActivityOptions. If the activity failed then server
191-
// would attempt to dispatch another activity task to retry according to the retry policy. If there was heartbeat
189+
// GetHeartbeatDetails extracts heartbeat details from the last failed attempt. This is used in combination with the retry policy.
190+
// An activity could be scheduled with an optional retry policy on ActivityOptions. If the activity failed, then server
191+
// would attempt to dispatch another activity task to retry according to the retry policy. If there were heartbeat
192192
// details reported by activity from the failed attempt, the details would be delivered along with the activity task for
193-
// retry attempt. Activity could extract the details by GetHeartbeatDetails() and resume from the progress.
193+
// the retry attempt. An activity can extract the details from GetHeartbeatDetails() and resume progress from there.
194194
//
195-
// Note, values should not be reused for extraction here because merging on top
196-
// of existing values may result in unexpected behavior similar to
197-
// json.Unmarshal.
195+
// Note: Values should not be reused for extraction here because merging on top
196+
// of existing values may result in unexpected behavior similar to json.Unmarshal.
198197
func GetHeartbeatDetails(ctx context.Context, d ...interface{}) error {
199198
return getActivityOutboundInterceptor(ctx).GetHeartbeatDetails(ctx, d...)
200199
}
201200

202-
// GetActivityLogger returns a logger that can be used in activity
201+
// GetActivityLogger returns a logger that can be used in the activity.
203202
func GetActivityLogger(ctx context.Context) log.Logger {
204203
return getActivityOutboundInterceptor(ctx).GetLogger(ctx)
205204
}
206205

207-
// GetActivityMetricsHandler returns a metrics handler that can be used in activity
206+
// GetActivityMetricsHandler returns a metrics handler that can be used in the activity.
208207
func GetActivityMetricsHandler(ctx context.Context) metrics.Handler {
209208
return getActivityOutboundInterceptor(ctx).GetMetricsHandler(ctx)
210209
}
211210

212211
// GetWorkerStopChannel returns a read-only channel. The closure of this channel indicates the activity worker is stopping.
213212
// When the worker is stopping, it will close this channel and wait until the worker stop timeout finishes. After the timeout
214-
// hit, the worker will cancel the activity context and then exit. The timeout can be defined by worker option: WorkerStopTimeout.
215-
// Use this channel to handle activity graceful exit when the activity worker stops.
213+
// hits, the worker will cancel the activity context and then exit. The timeout can be defined by worker option: WorkerStopTimeout.
214+
// Use this channel to handle a graceful activity exit when the activity worker stops.
216215
func GetWorkerStopChannel(ctx context.Context) <-chan struct{} {
217216
return getActivityOutboundInterceptor(ctx).GetWorkerStopChannel(ctx)
218217
}
219218

220-
// RecordActivityHeartbeat sends heartbeat for the currently executing activity
221-
// If the activity is either canceled (or) workflow/activity doesn't exist then we would cancel
219+
// RecordActivityHeartbeat sends a heartbeat for the currently executing activity.
220+
// If the activity is either canceled or workflow/activity doesn't exist, then we would cancel
222221
// the context with error context.Canceled.
223222
//
224223
// TODO: we don't have a way to distinguish between the two cases when context is canceled because
225224
// context doesn't support overriding value of ctx.Error.
226225
// TODO: Implement automatic heartbeating with cancellation through ctx.
227226
//
228-
// details - the details that you provided here can be seen in the workflow when it receives TimeoutError, you
227+
// details - The details that you provided here can be seen in the workflow when it receives TimeoutError. You
229228
// can check error TimeoutType()/Details().
230229
func RecordActivityHeartbeat(ctx context.Context, details ...interface{}) {
231230
getActivityOutboundInterceptor(ctx).RecordHeartbeat(ctx, details...)

0 commit comments

Comments
 (0)
Please sign in to comment.