Skip to content

Commit 17b9bcc

Browse files
committed
Fixes
1 parent 4ad56ca commit 17b9bcc

File tree

6 files changed

+32
-33
lines changed

6 files changed

+32
-33
lines changed

clients/resources/static/admin/admin.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/connectors/masterconn/connector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (c *Connector) SendNewSubmission(
4040
language string,
4141
fileName string,
4242
fileReader io.Reader,
43-
) (uint, error) {
43+
) (SubmissionID uint, err error) {
4444
r := c.connection.R()
4545
r.SetContext(ctx)
4646
r.SetFormData(map[string]string{

common/connectors/storageconn/structs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Request struct {
3232
// For any download, if DownloadBytes == false, the DownloadFolder should be specified
3333
DownloadFolder string `json:"-"`
3434

35-
// Specify a custom filename for the downloaded file. Can be empty
35+
// Specify a custom filename for the downloaded file. Can be nil for auto filename detection
3636
DownloadFilename *string `json:"-"`
3737

3838
// For downloads, DownloadHead can be specified so that only first DownloadHead bytes will be loaded

common/db/models/problem.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const (
1414
)
1515

1616
type Problem struct {
17-
ID uint `gorm:"primarykey" json:"id" yaml:"id"`
18-
CreatedAt time.Time `json:"created_at" yaml:"created_at"`
17+
ID uint `gorm:"primarykey" json:"ID" yaml:"ID"`
18+
CreatedAt time.Time `json:"created_at" yaml:"CreatedAt"`
1919
UpdatedAt time.Time `json:"updated_at" yaml:"updated_at"`
2020
DeletedAt gorm.DeletedAt `gorm:"index" json:"-" yaml:"-"`
2121

master/queue/jobgenerators/common.go

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,26 @@ func buildTestResult(job *invokerconn.Job, result *masterconn.InvokerJobResult)
2525
return testResult
2626
}
2727

28+
const (
29+
timeRoundFactor = 1000
30+
memoryRoundFactor = 1024
31+
)
32+
2833
func roundTime(time customfields.Time) *customfields.Time {
29-
roundFactor := customfields.Time(1000)
30-
if time < roundFactor {
31-
return &time
32-
}
33-
time = (time + roundFactor - 1) / roundFactor * roundFactor
34-
roundFactor *= roundFactor
35-
if time < roundFactor {
36-
return &time
37-
}
38-
time = (time + roundFactor - 1) / roundFactor * roundFactor
39-
return &time
34+
return roundValue(time, timeRoundFactor)
4035
}
4136

4237
func roundMemory(memory customfields.Memory) *customfields.Memory {
43-
memoryFactor := customfields.Memory(1024)
44-
if memory < memoryFactor {
45-
return &memory
46-
}
47-
memory = (memory + memoryFactor - 1) / memoryFactor * memoryFactor
48-
memoryFactor *= memoryFactor
49-
if memory < memoryFactor {
50-
return &memory
38+
return roundValue(memory, memoryRoundFactor)
39+
}
40+
41+
func roundValue[T ~uint64](value T, roundFactor T) *T {
42+
for _ = range 2 {
43+
if value < roundFactor {
44+
return &value
45+
}
46+
value = (value + roundFactor - 1) / roundFactor * roundFactor
47+
roundFactor *= roundFactor
5148
}
52-
memory = (memory + memoryFactor - 1) / memoryFactor * memoryFactor
53-
return &memory
49+
return &value
5450
}

master/queue/jobgenerators/icpc_generator.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (i *ICPCGenerator) NextJob() *invokerconn.Job {
6767
return job
6868
}
6969

70-
func (i *ICPCGenerator) hasFail() {
70+
func (i *ICPCGenerator) setFail() {
7171
for i.firstTestToGive <= i.problem.TestsNumber {
7272
i.internalTestResults[i.firstTestToGive] = models.TestResult{
7373
TestNumber: i.firstTestToGive,
@@ -112,38 +112,41 @@ func (i *ICPCGenerator) incTestedPrefix() (*models.Submission, error) {
112112
// compileJobCompleted must be done with acquired mutex
113113
func (i *ICPCGenerator) compileJobCompleted(job *invokerconn.Job, result *masterconn.InvokerJobResult) (*models.Submission, error) {
114114
if job.Type != invokerconn.CompileJob {
115-
logger.Panic("Treating %v as compile job", job.Type)
115+
logger.Panic("Treating job %d of type %v as compile job", job.ID, job.Type)
116116
}
117117
i.state = compilationFinished
118118
switch result.Verdict {
119119
case verdict.CD:
120120
// skip
121121
case verdict.CE:
122122
i.submission.Verdict = result.Verdict
123-
i.hasFail()
123+
i.setFail()
124124
default:
125125
i.internalTestResults[1] = models.TestResult{
126126
TestNumber: 1,
127127
Verdict: verdict.CF,
128128
Error: fmt.Sprintf("unknown verdict for compilation completed: %v", result.Verdict),
129129
}
130130
i.firstTestToGive++
131-
i.hasFail()
131+
i.setFail()
132132
}
133133
return i.incTestedPrefix()
134134
}
135135

136136
// testJobCompleted must be done with acquired mutex
137137
func (i *ICPCGenerator) testJobCompleted(job *invokerconn.Job, result *masterconn.InvokerJobResult) (*models.Submission, error) {
138+
if job.Type != invokerconn.TestJob {
139+
logger.Panic("Treating job %d of type %v as test job", job.ID, job.Type)
140+
}
138141
switch result.Verdict {
139142
case verdict.OK:
140143
// skip
141144
case verdict.PT, verdict.WA, verdict.RT, verdict.ML, verdict.TL, verdict.WL, verdict.SE, verdict.CF:
142-
i.hasFail()
145+
i.setFail()
143146
default:
144147
result.Verdict = verdict.CF
145148
result.Error = fmt.Sprintf("unknown verdict for test job: %v", result.Verdict)
146-
i.hasFail()
149+
i.setFail()
147150
}
148151
i.internalTestResults[job.Test] = buildTestResult(job, result)
149152
return i.incTestedPrefix()

0 commit comments

Comments
 (0)