@@ -27,6 +27,9 @@ func (repository *gormHeartbeatMonitorRepository) UpdateQueueID(ctx context.Cont
2727 ctx , span := repository .tracer .Start (ctx )
2828 defer span .End ()
2929
30+ ctx , cancel := context .WithTimeout (ctx , 1 * time .Second )
31+ defer cancel ()
32+
3033 err := repository .db .
3134 Model (& entities.HeartbeatMonitor {}).
3235 Where ("id = ?" , monitorID ).
@@ -45,6 +48,9 @@ func (repository *gormHeartbeatMonitorRepository) Delete(ctx context.Context, us
4548 ctx , span := repository .tracer .Start (ctx )
4649 defer span .End ()
4750
51+ ctx , cancel := context .WithTimeout (ctx , 1 * time .Second )
52+ defer cancel ()
53+
4854 err := repository .db .WithContext (ctx ).
4955 Where ("user_id = ?" , userID ).
5056 Where ("owner = ?" , owner ).
@@ -75,6 +81,9 @@ func (repository *gormHeartbeatMonitorRepository) Index(ctx context.Context, use
7581 ctx , span := repository .tracer .Start (ctx )
7682 defer span .End ()
7783
84+ ctx , cancel := context .WithTimeout (ctx , 1 * time .Second )
85+ defer cancel ()
86+
7887 query := repository .db .WithContext (ctx ).Where ("user_id = ?" , userID ).Where ("owner = ?" , owner )
7988 heartbeats := new ([]entities.Heartbeat )
8089 if err := query .Order ("timestamp DESC" ).Limit (params .Limit ).Offset (params .Skip ).Find (& heartbeats ).Error ; err != nil {
@@ -90,6 +99,9 @@ func (repository *gormHeartbeatMonitorRepository) Store(ctx context.Context, hea
9099 ctx , span := repository .tracer .Start (ctx )
91100 defer span .End ()
92101
102+ ctx , cancel := context .WithTimeout (ctx , 1 * time .Second )
103+ defer cancel ()
104+
93105 if err := repository .db .WithContext (ctx ).Create (heartbeatMonitor ).Error ; err != nil {
94106 msg := fmt .Sprintf ("cannot save heartbeatMonitor monitor with ID [%s]" , heartbeatMonitor .ID )
95107 return repository .tracer .WrapErrorSpan (span , stacktrace .Propagate (err , msg ))
@@ -103,6 +115,9 @@ func (repository *gormHeartbeatMonitorRepository) Load(ctx context.Context, user
103115 ctx , span := repository .tracer .Start (ctx )
104116 defer span .End ()
105117
118+ ctx , cancel := context .WithTimeout (ctx , 1 * time .Second )
119+ defer cancel ()
120+
106121 phone := new (entities.HeartbeatMonitor )
107122 err := repository .db .WithContext (ctx ).
108123 Where ("user_id = ?" , userID ).
@@ -127,6 +142,9 @@ func (repository *gormHeartbeatMonitorRepository) Exists(ctx context.Context, us
127142 ctx , span := repository .tracer .Start (ctx )
128143 defer span .End ()
129144
145+ ctx , cancel := context .WithTimeout (ctx , 1 * time .Second )
146+ defer cancel ()
147+
130148 var exists bool
131149 err := repository .db .WithContext (ctx ).
132150 Model (& entities.HeartbeatMonitor {}).
0 commit comments