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:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
page = fillPassengerDetails(page, name, gender, passport, passportExpiry, contact)
|
passthroughLaggingPage := false
|
||||||
log.Println("Passenger details filled.")
|
|
||||||
|
|
||||||
// Exits if context cancelled
|
for !passthroughLaggingPage {
|
||||||
select {
|
|
||||||
case <-timerCtx.Done():
|
filledPassengerDetailContext, filledPassengerDetails := context.WithTimeout(context.Background(), 15*time.Second)
|
||||||
browser.MustClose()
|
go func() {
|
||||||
return false
|
page = fillPassengerDetails(page, name, gender, passport, passportExpiry, contact)
|
||||||
default:
|
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
|
// // Start debug screenshots
|
||||||
// debugScreenshotCtx, cancelDebugScreenshot := context.WithCancel(context.Background())
|
// debugScreenshotCtx, cancelDebugScreenshot := context.WithCancel(context.Background())
|
||||||
// go takeDebugScreenshots(debugScreenshotCtx, courtPage)
|
// 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 done with debug screenshot
|
||||||
// defer cancelDebugScreenshot()
|
// defer cancelDebugScreenshot()
|
||||||
|
|
||||||
if !paymentSucceed {
|
|
||||||
log.Println("Payment failed.")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
_ = page
|
_ = page
|
||||||
|
|
||||||
@@ -310,7 +316,6 @@ func chooseAndMakePayment(timerCtx context.Context, creditCardType, creditCard,
|
|||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
log.Println("Recovering from chooseAndMakePayment panic...")
|
log.Println("Recovering from chooseAndMakePayment panic...")
|
||||||
cancelRefresh()
|
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):
|
case <-time.After(540 * time.Second):
|
||||||
log.Println("Reloading page")
|
log.Println("Reloading page")
|
||||||
page.MustReload()
|
page.MustReload()
|
||||||
|
page.MustWaitLoad()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
return cancelFunc
|
return cancelFunc
|
||||||
|
|||||||
Reference in New Issue
Block a user