mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-01 05:49:40 +08:00
change: update example llk
This commit is contained in:
@@ -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()
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
v5.0.0-beta-2506150042
|
v5.0.0-beta-2506150047
|
||||||
|
|||||||
Reference in New Issue
Block a user