Skip to content

Commit

Permalink
Implement retry (#3)
Browse files Browse the repository at this point in the history
Signed-off-by: Kotaro Inoue <k.musaino@gmail.com>

Signed-off-by: Kotaro Inoue <k.musaino@gmail.com>
  • Loading branch information
musaprg authored Dec 13, 2022
1 parent abfdf97 commit 19fd9be
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cmd/rarejobctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ var (
seleniumBrowserName = flag.String("selenium-browser-name", "firefox", "Remote Selenium Browser name")
)

const (
// maxRetryReservation is the number of retry when the reservation failes somehow.
maxRetryReservation = 5
)

func init() {
flag.Parse()
}
Expand Down Expand Up @@ -70,8 +75,16 @@ func main() {
from := time.Date(*year, time.Month(*month), *day, hour, minute, 0, 0, time.Local)
margin := 30 * time.Minute

var r *librarejob.Reserve

logger.Info("start reserving tutor", zap.Int("year", *year), zap.Int("month", *month), zap.Int("day", *day), zap.String("time", *t))
r, err := rc.ReserveTutor(context.TODO(), from, margin)
for attempt := 0; attempt < maxRetryReservation; attempt++ {
r, err = rc.ReserveTutor(context.TODO(), from, margin)
if err != nil {
logger.Warn("failed to reserve tutor. retrying...", zap.Error(err))
}
}

if err != nil {
api.PostMessage(os.Getenv("SLACK_CHANNEL"), slack.MsgOptionText("something went wrong... I failed to reserve your tutor. try again later.", false), slack.MsgOptionAsUser(true))
logger.Fatal("failed to reserve tutor", zap.Error(err))
Expand Down

0 comments on commit 19fd9be

Please sign in to comment.