Feat(booking-job): Auto timeout close browser
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:
@@ -169,6 +169,19 @@ func (env *Env) startBooking(job *Booking, username string, password string, cre
|
|||||||
defaultDevice.UserAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36"
|
defaultDevice.UserAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36"
|
||||||
browser := rod.New().ControlURL(u).MustConnect().DefaultDevice(defaultDevice)
|
browser := rod.New().ControlURL(u).MustConnect().DefaultDevice(defaultDevice)
|
||||||
|
|
||||||
|
// Close browser when context is done
|
||||||
|
go func() {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
log.Println("Recovering from browser panic...")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
<-timerCtx.Done()
|
||||||
|
log.Println("Timed out. Closing browser.")
|
||||||
|
browser.MustClose()
|
||||||
|
}()
|
||||||
|
|
||||||
// Defer closing browser
|
// Defer closing browser
|
||||||
defer browser.MustClose()
|
defer browser.MustClose()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user