Browse Source

Feat(booking-job): Handle seat retries

master
Samuel Pua 3 years ago
parent
commit
dcfa34176e
  1. 12
      backend/internal/ktmtrainbot/backgroundbookingjob.go

12
backend/internal/ktmtrainbot/backgroundbookingjob.go

@ -318,9 +318,8 @@ func (env *Env) startBooking(job *Booking, username string, password string, cre
// // Defer done with debug screenshot
// defer cancelDebugScreenshot()
time.Sleep(600 * time.Second)
time.Sleep(10 * time.Second)
_ = page
browser.MustClose()
return true
}
@ -435,6 +434,15 @@ func selectBookingSlot(ctx context.Context, page *rod.Page, timeCode string) *ro
time.Sleep(1000 * time.Millisecond)
}
// Repeat if there's no seats -- seats might be released later
if strings.Contains(bodyText, "Not enough seat for onward trip") {
completed = false
closeModalButton := page.MustElement("#popupModalCloseButton")
closeModalButton.Eval(`this.click()`)
time.Sleep(1000 * time.Millisecond)
}
styleAttribute := selectButtonElement.MustAttribute("style")
if styleAttribute == nil || !strings.Contains(*styleAttribute, "display: none") {
completed = false

Loading…
Cancel
Save