Feat(booking-job): Report ticket 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:
@@ -78,7 +78,7 @@ func (env *Env) BackgroundJobRunner() {
|
|||||||
// Create next run where it's not the past (either from old NextRun or now())
|
// Create next run where it's not the past (either from old NextRun or now())
|
||||||
timeNow := time.Now()
|
timeNow := time.Now()
|
||||||
startTime := time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 10, 0, 0, timeNow.Location())
|
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) {
|
if timeNow.After(startTime) && timeNow.Before(endTime) {
|
||||||
err := env.DB.Where(&user.Profile{UserID: jobToDo.UserID}).First(&jobToDo.User.Profile).Error
|
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()
|
page.MustActivate()
|
||||||
|
|
||||||
// Exits if context cancelled
|
// Exits if context cancelled
|
||||||
@@ -346,6 +354,7 @@ func selectBookingSlot(ctx context.Context, page *rod.Page, timeCode string) *ro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start probing
|
// Start probing
|
||||||
|
reportedTicketDetails := false
|
||||||
completed := false
|
completed := false
|
||||||
for !completed {
|
for !completed {
|
||||||
page.MustWaitLoad()
|
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
|
// Checks for context before clicking
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
|||||||
Reference in New Issue
Block a user