change: update example llk

This commit is contained in:
lilong.129
2025-06-15 00:47:20 +08:00
parent 69b4b92904
commit 4050fc3ffc
3 changed files with 40 additions and 3 deletions

View File

@@ -1,6 +1,10 @@
package main package main
import ( import (
"context"
"os"
"os/signal"
"syscall"
"time" "time"
hrp "github.com/httprunner/httprunner/v5" hrp "github.com/httprunner/httprunner/v5"
@@ -18,8 +22,36 @@ func main() {
} }
defer bot.Close() defer bot.Close()
// err = bot.EnterGame(context.Background()) err = bot.EnterGame(context.Background())
// require.NoError(t, err, "Failed to enter game") if err != nil {
log.Fatal().Err(err).Msg("Failed to enter game")
}
// Handle graceful shutdown and report generation
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Create channel to handle OS signals
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
// Start goroutine to handle signals
go func() {
<-sigChan
log.Info().Msg("Received shutdown signal, generating report...")
if err := bot.GenerateReport(); err != nil {
log.Error().Err(err).Msg("Failed to generate report")
}
cancel()
}()
// Start goroutine to handle context cancellation
go func() {
<-ctx.Done()
log.Info().Msg("Context cancelled, generating report...")
if err := bot.GenerateReport(); err != nil {
log.Error().Err(err).Msg("Failed to generate report")
}
}()
for { for {
err = bot.Play() err = bot.Play()

View File

@@ -223,12 +223,17 @@ func (bot *LLKGameBot) Play() error {
) )
if err != nil && !errors.Is(err, code.MaxRetryError) { if err != nil && !errors.Is(err, code.MaxRetryError) {
log.Error().Err(err).Msg("Failed to click game interface") log.Error().Err(err).Msg("Failed to click game interface")
return err
} }
} }
return nil return nil
} }
func (bot *LLKGameBot) GenerateReport() error {
return bot.Session.GenerateReport()
}
// Close cleans up resources // Close cleans up resources
func (bot *LLKGameBot) Close() error { func (bot *LLKGameBot) Close() error {
if bot.DriverExt != nil { if bot.DriverExt != nil {

View File

@@ -1 +1 @@
v5.0.0-beta-2506150042 v5.0.0-beta-2506150047