File tree Expand file tree Collapse file tree 4 files changed +37
-0
lines changed Expand file tree Collapse file tree 4 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -102,6 +102,11 @@ func GetInfo(ctx context.Context) Info {
102
102
return internal .GetActivityInfo (ctx )
103
103
}
104
104
105
+ // HasInfo returns if the context contains activity information
106
+ func HasInfo (ctx context.Context ) bool {
107
+ return internal .HasActivityInfo (ctx )
108
+ }
109
+
105
110
// GetLogger returns a logger that can be used in activity
106
111
func GetLogger (ctx context.Context ) * zap.Logger {
107
112
return internal .GetActivityLogger (ctx )
Original file line number Diff line number Diff line change @@ -224,6 +224,11 @@ func GetActivityInfo(ctx context.Context) ActivityInfo {
224
224
}
225
225
}
226
226
227
+ // HasActivityInfo returns if the context contains activity information
228
+ func HasActivityInfo (ctx context.Context ) bool {
229
+ return hasActivityEnv (ctx )
230
+ }
231
+
227
232
// HasHeartbeatDetails checks if there is heartbeat details from last attempt.
228
233
func HasHeartbeatDetails (ctx context.Context ) bool {
229
234
env := getActivityEnv (ctx )
Original file line number Diff line number Diff line change @@ -233,3 +233,25 @@ func (s *activityTestSuite) TestGetWorkerStopChannel() {
233
233
channel := GetWorkerStopChannel (ctx )
234
234
s .NotNil (channel )
235
235
}
236
+
237
+ func (s * activityTestSuite ) TestHasActivityInfo () {
238
+ // Test context without activity info
239
+ ctx := context .Background ()
240
+ s .False (HasActivityInfo (ctx ))
241
+
242
+ // Test context with activity info
243
+ activityEnv := & activityEnvironment {
244
+ activityID : "test-activity-id" ,
245
+ activityType : ActivityType {Name : "test-activity-type" },
246
+ }
247
+ ctxWithActivity := context .WithValue (ctx , activityEnvContextKey , activityEnv )
248
+ s .True (HasActivityInfo (ctxWithActivity ))
249
+
250
+ // Test context with nil activity env
251
+ ctxWithNilActivity := context .WithValue (ctx , activityEnvContextKey , nil )
252
+ s .False (HasActivityInfo (ctxWithNilActivity ))
253
+
254
+ // Test context with other values in context
255
+ ctxWithOtherValue := context .WithValue (ctx , activityOptionsContextKey , "other-value" )
256
+ s .False (HasActivityInfo (ctxWithOtherValue ))
257
+ }
Original file line number Diff line number Diff line change @@ -155,6 +155,11 @@ func getActivityEnv(ctx context.Context) *activityEnvironment {
155
155
return env .(* activityEnvironment )
156
156
}
157
157
158
+ func hasActivityEnv (ctx context.Context ) bool {
159
+ env := ctx .Value (activityEnvContextKey )
160
+ return env != nil
161
+ }
162
+
158
163
func getActivityOptions (ctx Context ) * activityOptions {
159
164
eap := ctx .Value (activityOptionsContextKey )
160
165
if eap == nil {
You can’t perform that action at this time.
0 commit comments