Feat(booking-job): Report ticket details
All checks were successful
ktm-booking-bot/ktm-booking-bot/pipeline/head This commit looks good

This commit is contained in:
2022-09-28 23:57:46 +08:00
parent ca5940ce64
commit 8da6376f31

View File

@@ -78,7 +78,7 @@ func (env *Env) BackgroundJobRunner() {
// Create next run where it's not the past (either from old NextRun or now())
timeNow := time.Now()
startTime := time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 10, 0, 0, timeNow.Location())
endTime := time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 16, 0, 0, timeNow.Location())
endTime := startTime.Add(10 * time.Minute)
if timeNow.After(startTime) && timeNow.Before(endTime) {
err := env.DB.Where(&user.Profile{UserID: jobToDo.UserID}).First(&jobToDo.User.Profile).Error
@@ -221,7 +221,15 @@ func (env *Env) startBooking(job *Booking, username string, password string, cre
}()
}
page = <-pageChan
// Wait for either page received or timeout
select {
case page = <-pageChan:
log.Println("Page received.")
case <-getBookingSlotCtx.Done():
log.Println("Context cancelled.")
browser.MustClose()
return false
}
page.MustActivate()
// Exits if context cancelled
@@ -346,6 +354,7 @@ func selectBookingSlot(ctx context.Context, page *rod.Page, timeCode string) *ro
}
// Start probing
reportedTicketDetails := false
completed := false
for !completed {
page.MustWaitLoad()
@@ -359,6 +368,12 @@ func selectBookingSlot(ctx context.Context, page *rod.Page, timeCode string) *ro
}
}
if !reportedTicketDetails {
ticketDetails := rowElement.MustText()
log.Printf("Ticket Details: %s", ticketDetails)
reportedTicketDetails = true
}
// Checks for context before clicking
select {
case <-ctx.Done():