mirror of
https://github.com/postmannen/ctrl.git
synced 2025-03-05 14:56:49 +00:00
changed cancelation
This commit is contained in:
parent
7c991ee3d5
commit
c6ecb1b868
1 changed files with 9 additions and 5 deletions
14
requests.go
14
requests.go
|
@ -682,7 +682,8 @@ func (m methodREQCopyFileFrom) handler(proc process, message Message, node strin
|
||||||
DstNode := message.MethodArgs[1]
|
DstNode := message.MethodArgs[1]
|
||||||
DstFilePath := message.MethodArgs[2]
|
DstFilePath := message.MethodArgs[2]
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(proc.ctx, time.Second*2)
|
ctx, cancel := context.WithTimeout(proc.ctx, time.Second*time.Duration(message.MethodTimeout))
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
outCh := make(chan []byte)
|
outCh := make(chan []byte)
|
||||||
errCh := make(chan error)
|
errCh := make(chan error)
|
||||||
|
@ -740,7 +741,7 @@ func (m methodREQCopyFileFrom) handler(proc process, message Message, node strin
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
fmt.Printf(" ** DEBUG: got ctx.Done\n")
|
fmt.Printf(" ** DEBUG: got ctx.Done\n")
|
||||||
cancel()
|
|
||||||
er := fmt.Errorf("error: methodREQCopyFile: got <-ctx.Done(): %v", message.MethodArgs)
|
er := fmt.Errorf("error: methodREQCopyFile: got <-ctx.Done(): %v", message.MethodArgs)
|
||||||
sendErrorLogMessage(proc.configuration, proc.processes.metrics, proc.toRingbufferCh, proc.node, er)
|
sendErrorLogMessage(proc.configuration, proc.processes.metrics, proc.toRingbufferCh, proc.node, er)
|
||||||
|
|
||||||
|
@ -748,12 +749,10 @@ func (m methodREQCopyFileFrom) handler(proc process, message Message, node strin
|
||||||
case er := <-errCh:
|
case er := <-errCh:
|
||||||
fmt.Printf(" ** DEBUG: received on errCh: <-errCh\n")
|
fmt.Printf(" ** DEBUG: received on errCh: <-errCh\n")
|
||||||
sendErrorLogMessage(proc.configuration, proc.processes.metrics, proc.toRingbufferCh, proc.node, er)
|
sendErrorLogMessage(proc.configuration, proc.processes.metrics, proc.toRingbufferCh, proc.node, er)
|
||||||
cancel()
|
|
||||||
|
|
||||||
return
|
return
|
||||||
case out := <-outCh:
|
case out := <-outCh:
|
||||||
fmt.Printf(" ** DEBUG: got data on out channel: case out:=<-outCh\n")
|
fmt.Printf(" ** DEBUG: got data on out channel: case out:=<-outCh\n")
|
||||||
cancel()
|
|
||||||
|
|
||||||
dstDir := filepath.Dir(DstFilePath)
|
dstDir := filepath.Dir(DstFilePath)
|
||||||
dstFile := filepath.Base(DstFilePath)
|
dstFile := filepath.Base(DstFilePath)
|
||||||
|
@ -780,13 +779,18 @@ func (m methodREQCopyFileFrom) handler(proc process, message Message, node strin
|
||||||
log.Printf("%v\n", er)
|
log.Printf("%v\n", er)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf(" * DEBUG: sending SAM: %#v\n", sam)
|
fmt.Printf(" ** DEBUG: sending SAM: %#v\n", sam)
|
||||||
|
|
||||||
proc.toRingbufferCh <- []subjectAndMessage{sam}
|
proc.toRingbufferCh <- []subjectAndMessage{sam}
|
||||||
|
|
||||||
// TODO: Should we also send a reply message with the result back
|
// TODO: Should we also send a reply message with the result back
|
||||||
// to where the message originated ?
|
// to where the message originated ?
|
||||||
|
|
||||||
|
replyData := fmt.Sprintf("info: succesfully read the file %v, and sent the content to %v\n", SrcFilePath, DstNode)
|
||||||
|
|
||||||
|
newReplyMessage(proc, message, []byte(replyData))
|
||||||
|
|
||||||
|
fmt.Printf(" ** DEBUG: sent reply message\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Add table
Reference in a new issue