2024-07-16 06:53:57 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-07-17 06:10:04 +00:00
|
|
|
"time"
|
|
|
|
|
2024-09-11 15:58:02 +00:00
|
|
|
"github.com/samber/lo"
|
|
|
|
|
2024-07-16 06:53:57 +00:00
|
|
|
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
|
|
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/gap"
|
|
|
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
|
|
|
)
|
|
|
|
|
|
|
|
func PushCommand(userId uint, task models.UnifiedCommand) {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
pc := gap.H.GetDealerGrpcConn()
|
|
|
|
_, _ = proto.NewStreamControllerClient(pc).PushStream(ctx, &proto.PushStreamRequest{
|
2024-08-23 11:36:11 +00:00
|
|
|
UserId: lo.ToPtr(uint64(userId)),
|
2024-07-16 06:53:57 +00:00
|
|
|
Body: task.Marshal(),
|
|
|
|
})
|
|
|
|
}
|
2024-07-17 06:10:04 +00:00
|
|
|
|
|
|
|
func PushCommandBatch(userId []uint64, task models.UnifiedCommand) {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
pc := gap.H.GetDealerGrpcConn()
|
|
|
|
_, _ = proto.NewStreamControllerClient(pc).PushStreamBatch(ctx, &proto.PushStreamBatchRequest{
|
|
|
|
UserId: userId,
|
|
|
|
Body: task.Marshal(),
|
|
|
|
})
|
|
|
|
}
|