Skip to content

Commit b1aecd1

Browse files
committed
Refreshes submissions daily and after signup
1 parent 1a19362 commit b1aecd1

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

models/user.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ func AddUser(u User) (string, error) {
8585
log.Println(err)
8686
return "", errors.New("Could not create user: Username already exists")
8787
}
88+
err = RefreshSubmissions()
89+
//handle error
90+
8891
return u.ID.Hex(), nil
8992
}
9093

@@ -471,3 +474,26 @@ func CompareUser(uid1 bson.ObjectId, uid2 string) (Follow.AllWorldRanks, error)
471474
return worldRanksComparison, errors.New("UID Invalid")
472475
}
473476
}
477+
478+
func RefreshSubmissions() error {
479+
users := GetAllUsers()
480+
websites := [4]string{"codechef","codeforces","spoj","hackerrank"}
481+
var ErrorSubmissions error
482+
483+
//establishing a goroutine for this "for" loop
484+
for _ , user := range users {
485+
// executing every iteration in a separate goroutine (to be implemented later)
486+
// go func(user User) {
487+
for _ , website := range websites {
488+
err := AddSubmissions(&user, website)
489+
if err != nil {
490+
//Submissions for this particular user is not updated
491+
ErrorSubmissions = errors.New("Submission fetching altered")
492+
} else {
493+
continue
494+
}
495+
}
496+
// }(user)
497+
}
498+
return ErrorSubmissions
499+
}

services/scheduler/scheduler.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@ package scheduler
22

33
import (
44
"github.com/jasonlvhit/gocron"
5+
"github.com/mdg-iitr/Codephile/models"
6+
// "github.com/mdg-iitr/Codephile/models"
7+
58
)
69

710
func task() {
811
//Updates profiles and submissions
12+
_ = models.RefreshSubmissions()
13+
//handle error
914
}
1015

1116
func taskWithParams(a int, b string) {
1217
//
1318
}
1419

1520
func StartScheduling() {
16-
// gocron.Every(5).Seconds().Do(task)
21+
// task()
22+
// gocron.Every(10).Seconds().Do(task)
1723
gocron.Every(1).Day().Do(task) //task to be done everyday
1824
<- gocron.Start()
1925
}

0 commit comments

Comments
 (0)