Skip to content

Commit a19a8cd

Browse files
committed
fix cron
1 parent 8e891f7 commit a19a8cd

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

bot/happiness_survey.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func (s *Slack) GetTimeAndUsersHappinessSurvey() error {
101101
}
102102
}
103103
defer rows.Close()
104+
gocron.Clear()
104105
for rows.Next() {
105106
scheduledata := ScheduleData{}
106107
err = rows.Scan(&scheduledata.Times, &scheduledata.UserID)
@@ -112,7 +113,6 @@ func (s *Slack) GetTimeAndUsersHappinessSurvey() error {
112113
}
113114
channel := make(chan int)
114115
go startCron(channel)
115-
gocron.Clear()
116116
// get any error encountered during iteration
117117
err = rows.Err()
118118
if err != nil {
@@ -133,11 +133,6 @@ func (s *Slack) runHappinessSurveySchedule(times, userid string) {
133133
gocron.Every(1).Day().At(times).Do(s.askHappinessSurveyScheduled, userid)
134134
}
135135

136-
// Starts gocron
137-
func startCron(channel chan int) {
138-
<-gocron.Start()
139-
}
140-
141136
// Ask how are the users doing
142137
func (s *Slack) askHappinessSurveyScheduled(userid string) error {
143138

@@ -184,3 +179,8 @@ func (s *Slack) askHappinessSurveyScheduled(userid string) error {
184179
fmt.Printf("Scheduled happyness survey for user %s posted", userid)
185180
return nil
186181
}
182+
183+
// Starts gocron
184+
func startCron(channel chan int) {
185+
<-gocron.Start()
186+
}

0 commit comments

Comments
 (0)