Skip to content

Commit

Permalink
refactor(huawei): add context parameter to PushToHuawei function (#777)
Browse files Browse the repository at this point in the history
- Add context parameter to `PushToHuawei` function calls
- Update `PushToHuawei` function signature to include context parameter
- Replace `context.Background()` with passed context in `SendMessage` call

Signed-off-by: appleboy <appleboy.tw@gmail.com>
  • Loading branch information
appleboy authored Jun 15, 2024
1 parent e70a94e commit 651f59d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func main() {
return
}

if _, err := notify.PushToHuawei(req, cfg); err != nil {
if _, err := notify.PushToHuawei(g.ShutdownContext(), req, cfg); err != nil {
return
}

Expand Down
2 changes: 1 addition & 1 deletion notify/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func SendNotification(
case core.PlatFormAndroid:
resp, err = PushToAndroid(ctx, v, cfg)
case core.PlatFormHuawei:
resp, err = PushToHuawei(v, cfg)
resp, err = PushToHuawei(ctx, v, cfg)
}

if cfg.Core.FeedbackURL != "" {
Expand Down
4 changes: 2 additions & 2 deletions notify/notification_hms.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func GetHuaweiNotification(req *PushNotification) (*model.MessageRequest, error)
}

// PushToHuawei provide send notification to Android server.
func PushToHuawei(req *PushNotification, cfg *config.ConfYaml) (resp *ResponsePush, err error) {
func PushToHuawei(ctx context.Context, req *PushNotification, cfg *config.ConfYaml) (resp *ResponsePush, err error) {
logx.LogAccess.Debug("Start push notification for Huawei")

var (
Expand Down Expand Up @@ -192,7 +192,7 @@ Retry:

notification, _ := GetHuaweiNotification(req)

res, err := client.SendMessage(context.Background(), notification)
res, err := client.SendMessage(ctx, notification)
if err != nil {
// Send Message error
errLog := logPush(cfg, core.FailedPush, req.Topic, req, err)
Expand Down

0 comments on commit 651f59d

Please sign in to comment.