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 {
102102 return internal .GetActivityInfo (ctx )
103103}
104104
105+ // HasInfo returns if the context contains activity information
106+ func HasInfo (ctx context.Context ) bool {
107+ return internal .HasActivityInfo (ctx )
108+ }
109+
105110// GetLogger returns a logger that can be used in activity
106111func GetLogger (ctx context.Context ) * zap.Logger {
107112 return internal .GetActivityLogger (ctx )
Original file line number Diff line number Diff line change @@ -224,6 +224,11 @@ func GetActivityInfo(ctx context.Context) ActivityInfo {
224224 }
225225}
226226
227+ // HasActivityInfo returns if the context contains activity information
228+ func HasActivityInfo (ctx context.Context ) bool {
229+ return hasActivityEnv (ctx )
230+ }
231+
227232// HasHeartbeatDetails checks if there is heartbeat details from last attempt.
228233func HasHeartbeatDetails (ctx context.Context ) bool {
229234 env := getActivityEnv (ctx )
Original file line number Diff line number Diff line change @@ -233,3 +233,25 @@ func (s *activityTestSuite) TestGetWorkerStopChannel() {
233233 channel := GetWorkerStopChannel (ctx )
234234 s .NotNil (channel )
235235}
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 {
155155 return env .(* activityEnvironment )
156156}
157157
158+ func hasActivityEnv (ctx context.Context ) bool {
159+ env := ctx .Value (activityEnvContextKey )
160+ return env != nil
161+ }
162+
158163func getActivityOptions (ctx Context ) * activityOptions {
159164 eap := ctx .Value (activityOptionsContextKey )
160165 if eap == nil {
You can’t perform that action at this time.
0 commit comments