@@ -39,13 +39,11 @@ func (repository *gormHeartbeatMonitorRepository) DeleteAllForUser(ctx context.C
3939 ctx , span := repository .tracer .Start (ctx )
4040 defer span .End ()
4141
42- return executeWithRetry (func () error {
43- if err := repository .db .WithContext (ctx ).Where ("user_id = ?" , userID ).Delete (& entities.HeartbeatMonitor {}).Error ; err != nil {
44- msg := fmt .Sprintf ("cannot delete all [%T] for user with ID [%s]" , & entities.HeartbeatMonitor {}, userID )
45- return repository .tracer .WrapErrorSpan (span , stacktrace .Propagate (err , msg ))
46- }
47- return nil
48- })
42+ if err := repository .db .WithContext (ctx ).Where ("user_id = ?" , userID ).Delete (& entities.HeartbeatMonitor {}).Error ; err != nil {
43+ msg := fmt .Sprintf ("cannot delete all [%T] for user with ID [%s]" , & entities.HeartbeatMonitor {}, userID )
44+ return repository .tracer .WrapErrorSpan (span , stacktrace .Propagate (err , msg ))
45+ }
46+ return nil
4947}
5048
5149// UpdatePhoneOnline updates the online status of a phone
@@ -56,16 +54,14 @@ func (repository *gormHeartbeatMonitorRepository) UpdatePhoneOnline(ctx context.
5654 ctx , cancel := context .WithTimeout (ctx , dbOperationDuration )
5755 defer cancel ()
5856
59- err := executeWithRetry (func () error {
60- return repository .db .
61- Model (& entities.HeartbeatMonitor {}).
62- Where ("id = ?" , monitorID ).
63- Where ("user_id = ?" , userID ).
64- Updates (map [string ]any {
65- "phone_online" : isOnline ,
66- "updated_at" : time .Now ().UTC (),
67- }).Error
68- })
57+ err := repository .db .
58+ Model (& entities.HeartbeatMonitor {}).
59+ Where ("id = ?" , monitorID ).
60+ Where ("user_id = ?" , userID ).
61+ Updates (map [string ]any {
62+ "phone_online" : isOnline ,
63+ "updated_at" : time .Now ().UTC (),
64+ }).Error
6965 if err != nil {
7066 msg := fmt .Sprintf ("cannot update heartbeat monitor ID [%s] for user [%s]" , monitorID , userID )
7167 return repository .tracer .WrapErrorSpan (span , stacktrace .Propagate (err , msg ))
@@ -81,15 +77,13 @@ func (repository *gormHeartbeatMonitorRepository) UpdateQueueID(ctx context.Cont
8177 ctx , cancel := context .WithTimeout (ctx , dbOperationDuration )
8278 defer cancel ()
8379
84- err := executeWithRetry (func () error {
85- return repository .db .
86- Model (& entities.HeartbeatMonitor {}).
87- Where ("id = ?" , monitorID ).
88- Updates (map [string ]any {
89- "queue_id" : queueID ,
90- "updated_at" : time .Now ().UTC (),
91- }).Error
92- })
80+ err := repository .db .
81+ Model (& entities.HeartbeatMonitor {}).
82+ Where ("id = ?" , monitorID ).
83+ Updates (map [string ]any {
84+ "queue_id" : queueID ,
85+ "updated_at" : time .Now ().UTC (),
86+ }).Error
9387 if err != nil {
9488 msg := fmt .Sprintf ("cannot update heartbeat monitor ID [%s]" , monitorID )
9589 return repository .tracer .WrapErrorSpan (span , stacktrace .Propagate (err , msg ))
@@ -104,12 +98,10 @@ func (repository *gormHeartbeatMonitorRepository) Delete(ctx context.Context, us
10498 ctx , cancel := context .WithTimeout (ctx , dbOperationDuration )
10599 defer cancel ()
106100
107- err := executeWithRetry (func () error {
108- return repository .db .WithContext (ctx ).
109- Where ("user_id = ?" , userID ).
110- Where ("owner = ?" , owner ).
111- Delete (& entities.HeartbeatMonitor {}).Error
112- })
101+ err := repository .db .WithContext (ctx ).
102+ Where ("user_id = ?" , userID ).
103+ Where ("owner = ?" , owner ).
104+ Delete (& entities.HeartbeatMonitor {}).Error
113105 if err != nil {
114106 msg := fmt .Sprintf ("cannot delete heartbeat monitor with owner [%s] and userID [%s]" , owner , userID )
115107 return repository .tracer .WrapErrorSpan (span , stacktrace .Propagate (err , msg ))
@@ -128,9 +120,7 @@ func (repository *gormHeartbeatMonitorRepository) Index(ctx context.Context, use
128120
129121 query := repository .db .WithContext (ctx ).Where ("user_id = ?" , userID ).Where ("owner = ?" , owner )
130122 heartbeats := new ([]entities.Heartbeat )
131- if err := executeWithRetry (func () error {
132- return query .Order ("timestamp DESC" ).Limit (params .Limit ).Offset (params .Skip ).Find (& heartbeats ).Error
133- }); err != nil {
123+ if err := query .Order ("timestamp DESC" ).Limit (params .Limit ).Offset (params .Skip ).Find (& heartbeats ).Error ; err != nil {
134124 msg := fmt .Sprintf ("cannot fetch heartbeats with owner [%s] and params [%+#v]" , owner , params )
135125 return nil , repository .tracer .WrapErrorSpan (span , stacktrace .Propagate (err , msg ))
136126 }
@@ -146,7 +136,7 @@ func (repository *gormHeartbeatMonitorRepository) Store(ctx context.Context, hea
146136 ctx , cancel := context .WithTimeout (ctx , dbOperationDuration )
147137 defer cancel ()
148138
149- if err := executeWithRetry ( func () error { return repository .db .WithContext (ctx ).Create (heartbeatMonitor ).Error }) ; err != nil {
139+ if err := repository .db .WithContext (ctx ).Create (heartbeatMonitor ).Error ; err != nil {
150140 msg := fmt .Sprintf ("cannot save heartbeatMonitor monitor with ID [%s]" , heartbeatMonitor .ID )
151141 return repository .tracer .WrapErrorSpan (span , stacktrace .Propagate (err , msg ))
152142 }
@@ -163,12 +153,10 @@ func (repository *gormHeartbeatMonitorRepository) Load(ctx context.Context, user
163153 defer cancel ()
164154
165155 phone := new (entities.HeartbeatMonitor )
166- err := executeWithRetry (func () error {
167- return repository .db .WithContext (ctx ).
168- Where ("user_id = ?" , userID ).
169- Where ("owner = ?" , owner ).
170- First (& phone ).Error
171- })
156+ err := repository .db .WithContext (ctx ).
157+ Where ("user_id = ?" , userID ).
158+ Where ("owner = ?" , owner ).
159+ First (& phone ).Error
172160 if errors .Is (err , gorm .ErrRecordNotFound ) {
173161 msg := fmt .Sprintf ("heartbeat monitor with userID [%s] and owner [%s] does not exist" , userID , owner )
174162 return nil , repository .tracer .WrapErrorSpan (span , stacktrace .PropagateWithCode (err , ErrCodeNotFound , msg ))
@@ -191,14 +179,12 @@ func (repository *gormHeartbeatMonitorRepository) Exists(ctx context.Context, us
191179 defer cancel ()
192180
193181 var exists bool
194- err := executeWithRetry (func () error {
195- return repository .db .WithContext (ctx ).
196- Model (& entities.HeartbeatMonitor {}).
197- Select ("count(*) > 0" ).
198- Where ("user_id = ?" , userID ).
199- Where ("id = ?" , monitorID ).
200- Find (& exists ).Error
201- })
182+ err := repository .db .WithContext (ctx ).
183+ Model (& entities.HeartbeatMonitor {}).
184+ Select ("count(*) > 0" ).
185+ Where ("user_id = ?" , userID ).
186+ Where ("id = ?" , monitorID ).
187+ Find (& exists ).Error
202188 if err != nil {
203189 msg := fmt .Sprintf ("cannot check if heartbeat monitor exists with userID [%s] and montior ID [%s]" , userID , monitorID )
204190 return exists , repository .tracer .WrapErrorSpan (span , stacktrace .Propagate (err , msg ))
0 commit comments