mirror of
https://github.com/ncarlier/webhookd.git
synced 2025-04-06 16:50:36 +00:00
chore(): improve log semantic
This commit is contained in:
parent
296ab6aaa3
commit
7433f69c92
|
@ -17,7 +17,7 @@ import (
|
|||
|
||||
var workID uint64
|
||||
|
||||
// WorkStatus is the status of a worload
|
||||
// WorkStatus is the status of a workload
|
||||
type WorkStatus int
|
||||
|
||||
const (
|
||||
|
@ -46,7 +46,7 @@ type WorkRequest struct {
|
|||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// NewWorkRequest creats new work request
|
||||
// NewWorkRequest creates new work request
|
||||
func NewWorkRequest(name, script, payload, output string, args []string, timeout int) *WorkRequest {
|
||||
w := &WorkRequest{
|
||||
ID: atomic.AddUint64(&workID, 1),
|
||||
|
@ -69,11 +69,11 @@ func (wr *WorkRequest) Terminate(err error) error {
|
|||
if err != nil {
|
||||
wr.Status = Error
|
||||
wr.Err = err
|
||||
logger.Info.Printf("job %s#%d done [ERROR]\n", wr.Name, wr.ID)
|
||||
logger.Info.Printf("hook %s#%d done [ERROR]\n", wr.Name, wr.ID)
|
||||
return err
|
||||
}
|
||||
wr.Status = Success
|
||||
logger.Info.Printf("job %s#%d done [SUCCESS]\n", wr.Name, wr.ID)
|
||||
logger.Info.Printf("hook %s#%d done [SUCCESS]\n", wr.Name, wr.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ func StartDispatcher(nworkers int) {
|
|||
go func() {
|
||||
worker := <-WorkerQueue
|
||||
|
||||
logger.Debug.Printf("dispatching job request: %s#%d", work.Name, work.ID)
|
||||
logger.Debug.Printf("dispatching hook request: %s#%d", work.Name, work.ID)
|
||||
worker <- work
|
||||
}()
|
||||
}
|
||||
|
|
|
@ -26,9 +26,9 @@ func (c *ChanWriter) Write(p []byte) (int, error) {
|
|||
// Run work request
|
||||
func Run(work *model.WorkRequest) error {
|
||||
work.Status = model.Running
|
||||
logger.Info.Printf("job %s#%d started...\n", work.Name, work.ID)
|
||||
logger.Debug.Printf("job %s#%d script: %s\n", work.Name, work.ID, work.Script)
|
||||
logger.Debug.Printf("job %s#%d parameter: %v\n", work.Name, work.ID, work.Args)
|
||||
logger.Info.Printf("hook %s#%d started...\n", work.Name, work.ID)
|
||||
logger.Debug.Printf("hook %s#%d script: %s\n", work.Name, work.ID, work.Script)
|
||||
logger.Debug.Printf("hook %s#%d parameter: %v\n", work.Name, work.ID, work.Args)
|
||||
|
||||
binary, err := exec.LookPath(work.Script)
|
||||
if err != nil {
|
||||
|
@ -48,7 +48,7 @@ func Run(work *model.WorkRequest) error {
|
|||
return work.Terminate(err)
|
||||
}
|
||||
defer logFile.Close()
|
||||
logger.Debug.Printf("job %s#%d output file: %s\n", work.Name, work.ID, logFile.Name())
|
||||
logger.Debug.Printf("hook %s#%d output file: %s\n", work.Name, work.ID, logFile.Name())
|
||||
|
||||
wLogFile := bufio.NewWriter(logFile)
|
||||
defer wLogFile.Flush()
|
||||
|
@ -83,7 +83,7 @@ func Run(work *model.WorkRequest) error {
|
|||
if !work.IsTerminated() {
|
||||
work.MessageChan <- []byte(line)
|
||||
} else {
|
||||
logger.Error.Printf("job %s#%d is over ; unable to write more data into the channel: %s\n", work.Name, work.ID, line)
|
||||
logger.Error.Printf("hook %s#%d is over ; unable to write more data into the channel: %s\n", work.Name, work.ID, line)
|
||||
break
|
||||
}
|
||||
// writing to outfile
|
||||
|
@ -93,14 +93,14 @@ func Run(work *model.WorkRequest) error {
|
|||
}
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
logger.Error.Printf("job %s#%d is unable to read script stdout: %v\n", work.Name, work.ID, err)
|
||||
logger.Error.Printf("hook %s#%d is unable to read script stdout: %v\n", work.Name, work.ID, err)
|
||||
}
|
||||
wg.Done()
|
||||
}(cmdReader)
|
||||
|
||||
// Start timeout timer
|
||||
timer := time.AfterFunc(time.Duration(work.Timeout)*time.Second, func() {
|
||||
logger.Warning.Printf("job %s#%d has timed out (%ds): killing process #%d ...\n", work.Name, work.ID, work.Timeout, cmd.Process.Pid)
|
||||
logger.Warning.Printf("hook %s#%d has timed out (%ds): killing process #%d ...\n", work.Name, work.ID, work.Timeout, cmd.Process.Pid)
|
||||
syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
|
||||
})
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ func (w Worker) Start() {
|
|||
select {
|
||||
case work := <-w.Work:
|
||||
// Receive a work request.
|
||||
logger.Debug.Printf("worker #%d received job request: %s#%d\n", w.ID, work.Name, work.ID)
|
||||
logger.Debug.Printf("worker #%d received hook request: %s#%d\n", w.ID, work.Name, work.ID)
|
||||
metric.Requests.Add(1)
|
||||
err := Run(&work)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue
Block a user