Update
This commit is contained in:
70
main.go
70
main.go
@@ -167,11 +167,22 @@ func (m *myservice) Execute(args []string, r <-chan svc.ChangeRequest, status ch
|
||||
|
||||
for _, chCfg := range runtimeChannels {
|
||||
chCfg := chCfg
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
runChannelWatcher(ctx, hostname, chCfg, out)
|
||||
}()
|
||||
|
||||
chunks := splitIDMap(chCfg.IDs, 20)
|
||||
for i, idsChunk := range chunks {
|
||||
workerCfg := ChannelConfig{
|
||||
Name: chCfg.Name,
|
||||
IDs: idsChunk,
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
go func(chunkNo int, cfg ChannelConfig) {
|
||||
defer wg.Done()
|
||||
log.Printf("[%s] Starte Watcher-Chunk %d/%d mit %d IDs",
|
||||
cfg.Name, chunkNo+1, len(chunks), len(cfg.IDs))
|
||||
runChannelWatcher(ctx, hostname, cfg, out)
|
||||
}(i, workerCfg)
|
||||
}
|
||||
}
|
||||
|
||||
status <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
|
||||
@@ -279,11 +290,22 @@ func runDebug(cfg *AgentConfig, state *AgentState) {
|
||||
|
||||
for _, chCfg := range runtimeChannels {
|
||||
chCfg := chCfg
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
runChannelWatcher(ctx, hostname, chCfg, out)
|
||||
}()
|
||||
|
||||
chunks := splitIDMap(chCfg.IDs, 20)
|
||||
for i, idsChunk := range chunks {
|
||||
workerCfg := ChannelConfig{
|
||||
Name: chCfg.Name,
|
||||
IDs: idsChunk,
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
go func(chunkNo int, cfg ChannelConfig) {
|
||||
defer wg.Done()
|
||||
log.Printf("[%s] Starte Watcher-Chunk %d/%d mit %d IDs",
|
||||
cfg.Name, chunkNo+1, len(chunks), len(cfg.IDs))
|
||||
runChannelWatcher(ctx, hostname, cfg, out)
|
||||
}(i, workerCfg)
|
||||
}
|
||||
}
|
||||
|
||||
elog.Info(ServiceLogInfo, "Debug-Modus läuft. Mit Strg+C beenden.")
|
||||
@@ -568,6 +590,34 @@ func sendBatch(client *http.Client, backendURL string, state *AgentState, enroll
|
||||
return false, fmt.Errorf("backend antwortete mit HTTP %d: %s", resp.StatusCode, strings.TrimSpace(string(body)))
|
||||
}
|
||||
|
||||
func splitIDMap(ids map[uint32]bool, maxPerChunk int) []map[uint32]bool {
|
||||
if maxPerChunk <= 0 {
|
||||
maxPerChunk = 20
|
||||
}
|
||||
|
||||
list := make([]int, 0, len(ids))
|
||||
for id := range ids {
|
||||
list = append(list, int(id))
|
||||
}
|
||||
sort.Ints(list)
|
||||
|
||||
var chunks []map[uint32]bool
|
||||
for start := 0; start < len(list); start += maxPerChunk {
|
||||
end := start + maxPerChunk
|
||||
if end > len(list) {
|
||||
end = len(list)
|
||||
}
|
||||
|
||||
chunk := make(map[uint32]bool, end-start)
|
||||
for _, id := range list[start:end] {
|
||||
chunk[uint32(id)] = true
|
||||
}
|
||||
chunks = append(chunks, chunk)
|
||||
}
|
||||
|
||||
return chunks
|
||||
}
|
||||
|
||||
func evtSubscribe(channelPath, query string, signal windows.Handle, flags uint32) (windows.Handle, error) {
|
||||
chPtr, err := windows.UTF16PtrFromString(channelPath)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user