forked from Dri0m/flashpoint-submission-system
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserviceutils.go
93 lines (79 loc) · 2.61 KB
/
serviceutils.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package service
import (
"context"
"sync"
"github.com/FlashpointProject/flashpoint-submission-system/constants"
"github.com/FlashpointProject/flashpoint-submission-system/types"
"github.com/FlashpointProject/flashpoint-submission-system/utils"
"github.com/sirupsen/logrus"
)
func dberr(err error) error {
return constants.DatabaseError{Err: err}
}
func perr(msg string, status int) error {
return constants.PublicError{Msg: msg, Status: status}
}
func resumableLog(ctx context.Context, resumableParams *types.ResumableParams) *logrus.Entry {
if resumableParams == nil {
panic("invalid arguments provided")
}
return utils.LogCtx(ctx).WithFields(logrus.Fields{
"resumableChunkNumber": resumableParams.ResumableChunkNumber,
"resumableChunkSize": resumableParams.ResumableChunkSize,
"resumableTotalSize": resumableParams.ResumableTotalSize,
"resumableIdentifier": resumableParams.ResumableIdentifier,
"resumableFilename": resumableParams.ResumableFilename,
"resumableRelativePath": resumableParams.ResumableRelativePath,
"resumableCurrentChunkSize": resumableParams.ResumableCurrentChunkSize,
"resumableTotalChunks": resumableParams.ResumableTotalChunks,
})
}
type SubmissionStatusKeeper struct {
m map[string]*types.SubmissionStatus
sync.Mutex
}
func (s *SubmissionStatusKeeper) SetReceived(tempName string) {
s.Lock()
defer s.Unlock()
s.m[tempName] = &types.SubmissionStatus{Status: constants.SubmissionStatusReceived}
}
func (s *SubmissionStatusKeeper) SetCopying(tempName string, message string) {
s.Lock()
defer s.Unlock()
s.m[tempName].Status = constants.SubmissionStatusCopying
s.m[tempName].Message = &message
}
func (s *SubmissionStatusKeeper) SetValidating(tempName string) {
s.Lock()
defer s.Unlock()
s.m[tempName].Status = constants.SubmissionStatusValidating
s.m[tempName].Message = nil
}
func (s *SubmissionStatusKeeper) SetFinalizing(tempName string) {
s.Lock()
defer s.Unlock()
s.m[tempName].Status = constants.SubmissionStatusFinalizing
s.m[tempName].Message = nil
}
func (s *SubmissionStatusKeeper) SetFailed(tempName, message string) {
s.Lock()
defer s.Unlock()
s.m[tempName].Status = constants.SubmissionStatusFailed
s.m[tempName].Message = &message
}
func (s *SubmissionStatusKeeper) SetSuccess(tempName string, sid int64) {
s.Lock()
defer s.Unlock()
s.m[tempName].Status = constants.SubmissionStatusSuccess
s.m[tempName].Message = nil
s.m[tempName].SubmissionID = &sid
}
func (s *SubmissionStatusKeeper) Get(tempName string) *types.SubmissionStatus {
s.Lock()
defer s.Unlock()
ss, ok := s.m[tempName]
if !ok {
return nil
}
return ss
}