mirror of
https://github.com/goharbor/harbor.git
synced 2024-10-08 10:18:03 +02:00
Close the open IO stream used by the job logger after job eixting
This commit is contained in:
parent
75e29782f6
commit
4cc9e0bf47
@ -12,6 +12,7 @@ import (
|
||||
//It used in the job to output logs to the logfile.
|
||||
type JobLogger struct {
|
||||
backendLogger *log.Logger
|
||||
streamRef *os.File
|
||||
}
|
||||
|
||||
//New logger
|
||||
@ -26,9 +27,20 @@ func New(logPath string, level string) logger.Interface {
|
||||
|
||||
return &JobLogger{
|
||||
backendLogger: backendLogger,
|
||||
streamRef: f,
|
||||
}
|
||||
}
|
||||
|
||||
//Close the opened io stream
|
||||
//Implements logger.Closer interface
|
||||
func (jl *JobLogger) Close() error {
|
||||
if jl.streamRef != nil {
|
||||
jl.streamRef.Close()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
//Debug ...
|
||||
func (jl *JobLogger) Debug(v ...interface{}) {
|
||||
jl.backendLogger.Debug(v...)
|
||||
|
@ -8,6 +8,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/vmware/harbor/src/common/dao"
|
||||
"github.com/vmware/harbor/src/common/models"
|
||||
"github.com/vmware/harbor/src/jobservice_v2/opm"
|
||||
|
||||
"github.com/vmware/harbor/src/jobservice_v2/errs"
|
||||
@ -59,6 +61,9 @@ func (rj *ReplicationJob) Run(ctx env.JobContext, params map[string]interface{})
|
||||
if v, ok := ctx.Get("email_from"); ok {
|
||||
fmt.Printf("Get prop form context: email_from=%s\n", v)
|
||||
}
|
||||
if u, err := dao.GetUser(models.User{}); err == nil {
|
||||
fmt.Printf("u=%#+v\n", u)
|
||||
}
|
||||
|
||||
/*if 1 != 0 {
|
||||
return errors.New("I suicide")
|
||||
|
9
src/jobservice_v2/logger/closer.go
Normal file
9
src/jobservice_v2/logger/closer.go
Normal file
@ -0,0 +1,9 @@
|
||||
// Copyright 2018 The Harbor Authors. All rights reserved.
|
||||
|
||||
package logger
|
||||
|
||||
//Closer defines method to close the open io stream used by logger.
|
||||
type Closer interface {
|
||||
//Close the opened io stream
|
||||
Close() error
|
||||
}
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/vmware/harbor/src/jobservice_v2/env"
|
||||
"github.com/vmware/harbor/src/jobservice_v2/errs"
|
||||
"github.com/vmware/harbor/src/jobservice_v2/job"
|
||||
"github.com/vmware/harbor/src/jobservice_v2/logger"
|
||||
"github.com/vmware/harbor/src/jobservice_v2/opm"
|
||||
)
|
||||
|
||||
@ -48,6 +49,11 @@ func (rj *RedisJob) Run(j *work.Job) error {
|
||||
runningJob = Wrap(rj.job)
|
||||
|
||||
defer func() {
|
||||
//Close open io stream first
|
||||
if closer, ok := execContext.GetLogger().(logger.Closer); ok {
|
||||
closer.Close()
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
return //nothing need to do
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user