Skip to content

Commit

Permalink
fix: ejudge poll size config
Browse files Browse the repository at this point in the history
  • Loading branch information
Gornak40 committed May 9, 2024
1 parent c45524f commit dc6733e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SQLITE_PATH = <PATH>
[server]
GIN_SECRET = <SECRET>
JWT_SECRET = <SECRET>
POLL_MAX_RUNS = 1000
POLL_DELAY_SECONDS = 10
REVIEW_LIMIT = 3
```
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type DBConfig struct {
type ServerConfig struct {
GinSecret string `ini:"GIN_SECRET"`
JWTSecret string `ini:"JWT_SECRET"`
PollMaxRuns int64 `ini:"POLL_MAX_RUNS"`
PollDelaySeconds int64 `ini:"POLL_DELAY_SECONDS"`
ReviewLimit int64 `ini:"REVIEW_LIMIT"`
}
Expand Down
2 changes: 1 addition & 1 deletion controller/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (s *Server) IndexPOST(c *gin.Context) {

func (s *Server) reviewValid(user string, contestID uint, problem string) error {
filter := fmt.Sprintf("login == '%s' && prob == '%s' && status == OK", user, problem)
runs, err := s.ej.GetContestRuns(contestID, filter)
runs, err := s.ej.GetContestRuns(contestID, filter, 1)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions controller/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func runStatusFromDB(dbStatus *models.Run) *ejudge.EjStatusChange {
}

func (s *Server) pollContest(dbContest *models.Contest) error {
runs, err := s.ej.GetContestRuns(dbContest.EjudgeID, "status == PR")
runs, err := s.ej.GetContestRuns(dbContest.EjudgeID, "status == PR", int(s.cfg.PollMaxRuns))
if err != nil {
return err
}
Expand Down Expand Up @@ -71,7 +71,7 @@ func (s *Server) pollContest(dbContest *models.Contest) error {
if err := s.ej.ChangeRunStatus(status); err != nil {
logrus.WithError(err).Error("failed to change run status")
}
logrus.WithField("runID", dbRun.EjudgeID).Info("run review is done")
logrus.WithField("runID", dbRun.EjudgeID).Info("run review done")
if err := s.db.Delete(&dbRun).Error; err != nil { //nolint:gosec // G601: Implicit memory aliasing in for loop.
logrus.WithError(err).Error("failed to delete run")
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/ejudge/runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ type EjRuns struct {
TotalRuns uint `json:"total_runs"`
}

func (ej *EjClient) GetContestRuns(id uint, filter string) (*EjRuns, error) {
func (ej *EjClient) GetContestRuns(id uint, filter string, count int) (*EjRuns, error) {
fieldMask := getFieldMask(ejRunID, ejUserLogin, ejUserName, ejResult, ejProbName)

params := url.Values{
"contest_id": {strconv.Itoa(int(id))},
"filter_expr": {filter},
"last_run": {strconv.Itoa(-count)}, // some ejudge stuff
"field_mask": {fieldMask},
}
answer, err := ej.shootEjAPIGet(context.TODO(), "ej/api/v1/master/list-runs-json", params)
Expand Down

0 comments on commit dc6733e

Please sign in to comment.