2024-07-16 14:53:57 +08:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-11-02 13:23:27 +08:00
|
|
|
"git.solsynth.dev/hypernet/nexus/pkg/nex"
|
2024-11-17 20:39:04 +08:00
|
|
|
"github.com/rs/zerolog/log"
|
2024-07-17 14:10:04 +08:00
|
|
|
"time"
|
|
|
|
|
2024-09-11 23:58:02 +08:00
|
|
|
"github.com/samber/lo"
|
|
|
|
|
2024-11-02 13:24:37 +08:00
|
|
|
"git.solsynth.dev/hypernet/messaging/pkg/internal/gap"
|
2024-11-02 13:40:37 +08:00
|
|
|
"git.solsynth.dev/hypernet/nexus/pkg/proto"
|
2024-07-16 14:53:57 +08:00
|
|
|
)
|
|
|
|
|
2024-11-02 13:23:27 +08:00
|
|
|
func PushCommand(userId uint, task nex.WebSocketPackage) {
|
2024-07-16 14:53:57 +08:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
2024-11-02 13:23:27 +08:00
|
|
|
pc := gap.Nx.GetNexusGrpcConn()
|
2024-11-17 20:39:04 +08:00
|
|
|
_, err := proto.NewStreamServiceClient(pc).PushStream(ctx, &proto.PushStreamRequest{
|
2024-08-23 19:36:11 +08:00
|
|
|
UserId: lo.ToPtr(uint64(userId)),
|
2024-07-16 14:53:57 +08:00
|
|
|
Body: task.Marshal(),
|
|
|
|
})
|
2024-11-17 20:39:04 +08:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Warn().Err(err).Msg("Failed to push websocket command to nexus...")
|
|
|
|
}
|
2024-07-16 14:53:57 +08:00
|
|
|
}
|
2024-07-17 14:10:04 +08:00
|
|
|
|
2024-11-02 13:23:27 +08:00
|
|
|
func PushCommandBatch(userId []uint64, task nex.WebSocketPackage) {
|
2024-07-17 14:10:04 +08:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
2024-11-02 13:23:27 +08:00
|
|
|
pc := gap.Nx.GetNexusGrpcConn()
|
2024-11-17 20:39:04 +08:00
|
|
|
_, err := proto.NewStreamServiceClient(pc).PushStreamBatch(ctx, &proto.PushStreamBatchRequest{
|
2024-07-17 14:10:04 +08:00
|
|
|
UserId: userId,
|
|
|
|
Body: task.Marshal(),
|
|
|
|
})
|
2024-11-17 20:39:04 +08:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Warn().Err(err).Msg("Failed to push websocket command to nexus in batches...")
|
|
|
|
}
|
2024-07-17 14:10:04 +08:00
|
|
|
}
|