@@ -29,6 +29,8 @@ import (
2929 "strings"
3030 "time"
3131
32+ "go.uber.org/zap"
33+
3234 "github.com/topfreegames/maestro/internal/core/ports"
3335
3436 "github.com/topfreegames/maestro/internal/core/entities/operation"
@@ -40,51 +42,61 @@ import (
4042
4143type OperationsHandler struct {
4244 operationManager ports.OperationManager
45+ logger * zap.Logger
4346 api.UnimplementedOperationsServiceServer
4447}
4548
4649func ProvideOperationsHandler (operationManager ports.OperationManager ) * OperationsHandler {
4750 return & OperationsHandler {
4851 operationManager : operationManager ,
52+ logger : zap .L ().
53+ With (zap .String ("component" , "handler" ), zap .String ("handler" , "operations_handler" )),
4954 }
5055}
5156
5257func (h * OperationsHandler ) ListOperations (ctx context.Context , request * api.ListOperationsRequest ) (* api.ListOperationsResponse , error ) {
5358 sortingOrder , err := extractSortingParameters (request .OrderBy )
5459 if err != nil {
60+ h .logger .Error ("error parsing sorting parameters" , zap .String ("schedulerName" , request .GetSchedulerName ()), zap .String ("orderBy" , request .OrderBy ), zap .Error (err ))
5561 return nil , status .Error (codes .InvalidArgument , err .Error ())
5662 }
5763
5864 pendingOperationEntities , err := h .operationManager .ListSchedulerPendingOperations (ctx , request .GetSchedulerName ())
5965 if err != nil {
66+ h .logger .Error ("error listing pending operations" , zap .String ("schedulerName" , request .GetSchedulerName ()), zap .Error (err ))
6067 return nil , status .Error (codes .Unknown , err .Error ())
6168 }
6269 sortOperationsByCreatedAt (pendingOperationEntities , sortingOrder )
6370
6471 pendingOperationResponse , err := h .fromOperationsToResponses (pendingOperationEntities )
6572 if err != nil {
73+ h .logger .Error ("error converting pending operations" , zap .String ("schedulerName" , request .GetSchedulerName ()), zap .Error (err ))
6674 return nil , status .Error (codes .Unknown , err .Error ())
6775 }
6876
6977 activeOperationEntities , err := h .operationManager .ListSchedulerActiveOperations (ctx , request .GetSchedulerName ())
7078 if err != nil {
79+ h .logger .Error ("error listing pending operations" , zap .String ("schedulerName" , request .GetSchedulerName ()), zap .Error (err ))
7180 return nil , status .Error (codes .Unknown , err .Error ())
7281 }
7382 sortOperationsByCreatedAt (activeOperationEntities , sortingOrder )
7483
7584 activeOperationResponses , err := h .fromOperationsToResponses (activeOperationEntities )
7685 if err != nil {
86+ h .logger .Error ("error converting active operations" , zap .String ("schedulerName" , request .GetSchedulerName ()), zap .Error (err ))
7787 return nil , status .Error (codes .Unknown , err .Error ())
7888 }
7989
8090 finishedOperationEntities , err := h .operationManager .ListSchedulerFinishedOperations (ctx , request .GetSchedulerName ())
8191 if err != nil {
92+ h .logger .Error ("error listing finished operations" , zap .String ("schedulerName" , request .GetSchedulerName ()), zap .Error (err ))
8293 return nil , status .Error (codes .Unknown , err .Error ())
8394 }
8495 sortOperationsByCreatedAt (finishedOperationEntities , sortingOrder )
8596
8697 finishedOperationResponse , err := h .fromOperationsToResponses (finishedOperationEntities )
8798 if err != nil {
99+ h .logger .Error ("error converting finished operations" , zap .String ("schedulerName" , request .GetSchedulerName ()), zap .Error (err ))
88100 return nil , status .Error (codes .Unknown , err .Error ())
89101 }
90102
@@ -98,6 +110,7 @@ func (h *OperationsHandler) ListOperations(ctx context.Context, request *api.Lis
98110func (h * OperationsHandler ) CancelOperation (ctx context.Context , request * api.CancelOperationRequest ) (* api.CancelOperationResponse , error ) {
99111 err := h .operationManager .EnqueueOperationCancellationRequest (ctx , request .SchedulerName , request .OperationId )
100112 if err != nil {
113+ h .logger .Error ("error cancelling operation" , zap .String ("schedulerName" , request .GetSchedulerName ()), zap .String ("operationId" , request .GetOperationId ()), zap .Error (err ))
101114 return nil , status .Error (codes .Unknown , err .Error ())
102115 }
103116
0 commit comments