From b277e50cd8d744a77b930a9639ed43ef56e1c84f Mon Sep 17 00:00:00 2001 From: Samuel Pua Date: Fri, 7 Oct 2022 00:45:35 +0800 Subject: [PATCH] Fix(booking-job): check before completing probe & reduce thread --- backend/internal/ktmtrainbot/backgroundbookingjob.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/internal/ktmtrainbot/backgroundbookingjob.go b/backend/internal/ktmtrainbot/backgroundbookingjob.go index 701ed9a..8822d0c 100644 --- a/backend/internal/ktmtrainbot/backgroundbookingjob.go +++ b/backend/internal/ktmtrainbot/backgroundbookingjob.go @@ -213,7 +213,7 @@ func (env *Env) startBooking(job *Booking, username string, password string, cre contact := job.Contact reverse := job.BackToSg - threadCount := 15 + threadCount := 10 for i := 0; i < threadCount; i++ { time.Sleep(time.Millisecond * 100) go func() { @@ -229,6 +229,9 @@ func (env *Env) startBooking(job *Booking, username string, password string, cre currPage = selectBookingSlot(getBookingSlotCtx, currPage, timeCode) log.Println("Booking slot selected.") + // Make sure page completes loading + currPage.MustWaitLoad() + select { case <-getBookingSlotCtx.Done(): return @@ -430,10 +433,16 @@ func selectBookingSlot(ctx context.Context, page *rod.Page, timeCode string) *ro 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 } else { log.Println("Completed probing") completed = true } + } // Checks for context before clicking