77 lines
1.4 KiB
Go
77 lines
1.4 KiB
Go
|
package main
|
||
|
|
||
|
//import "surdeus.su/core/ss/u"
|
||
|
import "surdeus.su/core/amo"
|
||
|
import "surdeus.su/core/cli/mtool"
|
||
|
import "encoding/json"
|
||
|
import "os"
|
||
|
import "log"
|
||
|
import "time"
|
||
|
|
||
|
type Updater[V, VR any] interface {
|
||
|
UpdateValues(*amo.Client, []V) (VR, error)
|
||
|
GetNameMul() string
|
||
|
GetFuncName() string
|
||
|
}
|
||
|
|
||
|
func RunUpdater[V, VR any, U Updater[V, VR]](
|
||
|
u U, flags *mtool.Flags,
|
||
|
) {
|
||
|
now := time.Now()
|
||
|
var (
|
||
|
opts DefaultFlags
|
||
|
)
|
||
|
MakeDefaultFlags(&opts, flags)
|
||
|
flags.Parse()
|
||
|
|
||
|
client, err := amo.NewClient(opts.SecretPath)
|
||
|
if err != nil {
|
||
|
log.Fatalf("NewAmoClient(...): %s\n", err)
|
||
|
}
|
||
|
|
||
|
values := []V{}
|
||
|
dec := json.NewDecoder(os.Stdin)
|
||
|
err = dec.Decode(&values)
|
||
|
if err != nil {
|
||
|
log.Fatalf("json.Decode(...): %s\n", err)
|
||
|
}
|
||
|
|
||
|
finish := RunForSliceInThreads[V](
|
||
|
opts.Threads, opts.MEPR,
|
||
|
values, func(thread int, s []V){
|
||
|
_, err := u.UpdateValues(client, s)
|
||
|
if err != nil {
|
||
|
log.Printf(
|
||
|
"thread(%d): %s(...): %s\n",
|
||
|
thread, u.GetFuncName(), err,
|
||
|
)
|
||
|
return
|
||
|
}
|
||
|
if opts.Verbose {
|
||
|
log.Printf(
|
||
|
"thread(%d): Updated %d %s\n",
|
||
|
thread, len(s), u.GetNameMul(),
|
||
|
)
|
||
|
}
|
||
|
},
|
||
|
)
|
||
|
<-finish
|
||
|
if opts.Verbose {
|
||
|
rm := client.API.RequestsMade()
|
||
|
/*log.Printf(
|
||
|
"Summarized got %d %s\n",
|
||
|
len(finalValues), g.GetNameMul(),
|
||
|
)*/
|
||
|
log.Printf(
|
||
|
"Made %d requests in process\n",
|
||
|
rm,
|
||
|
)
|
||
|
took := time.Since(now).Seconds()
|
||
|
log.Printf(
|
||
|
"Took %f seconds\n",
|
||
|
took,
|
||
|
)
|
||
|
log.Printf("RPS = %f\n", float64(rm)/took)
|
||
|
}
|
||
|
}
|