Feat(booking-job): Handle lagging timeout with passenger details
All checks were successful
ktm-booking-bot/ktm-booking-bot/pipeline/head This commit looks good
All checks were successful
ktm-booking-bot/ktm-booking-bot/pipeline/head This commit looks good
This commit is contained in:
@@ -264,19 +264,30 @@ func (env *Env) startBooking(job *Booking, username string, password string, cre
|
||||
default:
|
||||
}
|
||||
|
||||
page = fillPassengerDetails(page, name, gender, passport, passportExpiry, contact)
|
||||
log.Println("Passenger details filled.")
|
||||
passthroughLaggingPage := false
|
||||
|
||||
// Exits if context cancelled
|
||||
select {
|
||||
case <-timerCtx.Done():
|
||||
browser.MustClose()
|
||||
return false
|
||||
default:
|
||||
for !passthroughLaggingPage {
|
||||
|
||||
filledPassengerDetailContext, filledPassengerDetails := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
go func() {
|
||||
page = fillPassengerDetails(page, name, gender, passport, passportExpiry, contact)
|
||||
log.Println("Passenger details filled.")
|
||||
filledPassengerDetails()
|
||||
}()
|
||||
|
||||
<-filledPassengerDetailContext.Done()
|
||||
|
||||
passthroughLaggingPage = chooseAndMakePayment(timerCtx, creditCardType, creditCard, creditCardCVV, creditCardExpiry, browser, page)
|
||||
|
||||
// Exits if context cancelled
|
||||
select {
|
||||
case <-timerCtx.Done():
|
||||
browser.MustClose()
|
||||
return false
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
paymentSucceed := chooseAndMakePayment(timerCtx, creditCardType, creditCard, creditCardCVV, creditCardExpiry, browser, page)
|
||||
|
||||
// // Start debug screenshots
|
||||
// debugScreenshotCtx, cancelDebugScreenshot := context.WithCancel(context.Background())
|
||||
// go takeDebugScreenshots(debugScreenshotCtx, courtPage)
|
||||
@@ -284,11 +295,6 @@ func (env *Env) startBooking(job *Booking, username string, password string, cre
|
||||
// // Defer done with debug screenshot
|
||||
// defer cancelDebugScreenshot()
|
||||
|
||||
if !paymentSucceed {
|
||||
log.Println("Payment failed.")
|
||||
return false
|
||||
}
|
||||
|
||||
time.Sleep(10 * time.Second)
|
||||
_ = page
|
||||
|
||||
@@ -310,7 +316,6 @@ func chooseAndMakePayment(timerCtx context.Context, creditCardType, creditCard,
|
||||
if r := recover(); r != nil {
|
||||
log.Println("Recovering from chooseAndMakePayment panic...")
|
||||
cancelRefresh()
|
||||
chooseAndMakePayment(timerCtx, creditCardType, creditCard, creditCardCVV, creditCardExpiry, browser, page)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -642,6 +647,7 @@ func triggerFuturePageRefresh(page *rod.Page) func() {
|
||||
case <-time.After(540 * time.Second):
|
||||
log.Println("Reloading page")
|
||||
page.MustReload()
|
||||
page.MustWaitLoad()
|
||||
}
|
||||
}()
|
||||
return cancelFunc
|
||||
|
||||
Reference in New Issue
Block a user