-
Notifications
You must be signed in to change notification settings - Fork 41
/
event_sp_exit.go
51 lines (45 loc) · 1.22 KB
/
event_sp_exit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package bsdb
import (
"time"
"gorm.io/gorm"
)
// ListSpExitEvents list sp exit events
func (b *BsDBImpl) ListSpExitEvents(blockID uint64, spID uint32) (*EventStorageProviderExit, *EventCompleteStorageProviderExit, error) {
var (
event *EventStorageProviderExit
completeEvent *EventCompleteStorageProviderExit
err error
)
startTime := time.Now()
methodName := currentFunction()
defer func() {
if err != nil {
MetadataDatabaseFailureMetrics(err, startTime, methodName)
} else {
MetadataDatabaseSuccessMetrics(startTime, methodName)
}
}()
err = b.db.Table((&EventStorageProviderExit{}).TableName()).
Select("*").
Where("storage_provider_id = ? and create_at <= ?", spID, blockID).
Order("create_at desc").
Take(&event).Error
if err != nil {
if err == gorm.ErrRecordNotFound {
return nil, nil, nil
}
return nil, nil, err
}
err = b.db.Table((&EventCompleteStorageProviderExit{}).TableName()).
Select("*").
Where("storage_provider_id = ? and create_at <= ?", spID, blockID).
Order("create_at desc").
Take(&completeEvent).Error
if err != nil {
if err == gorm.ErrRecordNotFound {
return event, nil, nil
}
return nil, nil, err
}
return event, completeEvent, nil
}