Skip to content

Commit

Permalink
Refreshes submissions daily and after signup
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnesh07 committed Nov 3, 2019
1 parent 1a19362 commit b1aecd1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
26 changes: 26 additions & 0 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func AddUser(u User) (string, error) {
log.Println(err)
return "", errors.New("Could not create user: Username already exists")
}
err = RefreshSubmissions()
//handle error

return u.ID.Hex(), nil
}

Expand Down Expand Up @@ -471,3 +474,26 @@ func CompareUser(uid1 bson.ObjectId, uid2 string) (Follow.AllWorldRanks, error)
return worldRanksComparison, errors.New("UID Invalid")
}
}

func RefreshSubmissions() error {
users := GetAllUsers()
websites := [4]string{"codechef","codeforces","spoj","hackerrank"}
var ErrorSubmissions error

//establishing a goroutine for this "for" loop
for _ , user := range users {
// executing every iteration in a separate goroutine (to be implemented later)
// go func(user User) {
for _ , website := range websites {
err := AddSubmissions(&user, website)
if err != nil {
//Submissions for this particular user is not updated
ErrorSubmissions = errors.New("Submission fetching altered")
} else {
continue
}
}
// }(user)
}
return ErrorSubmissions
}
8 changes: 7 additions & 1 deletion services/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ package scheduler

import (
"github.com/jasonlvhit/gocron"
"github.com/mdg-iitr/Codephile/models"
// "github.com/mdg-iitr/Codephile/models"

)

func task() {
//Updates profiles and submissions
_ = models.RefreshSubmissions()
//handle error
}

func taskWithParams(a int, b string) {
//
}

func StartScheduling() {
// gocron.Every(5).Seconds().Do(task)
// task()
// gocron.Every(10).Seconds().Do(task)
gocron.Every(1).Day().Do(task) //task to be done everyday
<- gocron.Start()
}

0 comments on commit b1aecd1

Please sign in to comment.