mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 18:25:56 +01:00
fix issue: job context may be nil pointer when trying to be closed in defer func
This commit is contained in:
parent
1cb40368f5
commit
233692c127
@ -40,21 +40,7 @@ func (rj *RedisJob) Run(j *work.Job) error {
|
||||
execContext env.JobContext
|
||||
)
|
||||
|
||||
execContext, err = rj.buildContext(j)
|
||||
if err != nil {
|
||||
buildContextFailed = true
|
||||
goto FAILED //no need to retry
|
||||
}
|
||||
|
||||
//Wrap job
|
||||
runningJob = Wrap(rj.job)
|
||||
|
||||
defer func() {
|
||||
//Close open io stream first
|
||||
if closer, ok := execContext.GetLogger().(logger.Closer); ok {
|
||||
closer.Close()
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
logger.Infof("Job '%s:%s' exit with success", j.Name, j.ID)
|
||||
return //nothing need to do
|
||||
@ -85,6 +71,22 @@ func (rj *RedisJob) Run(j *work.Job) error {
|
||||
}
|
||||
}()
|
||||
|
||||
//Wrap job
|
||||
runningJob = Wrap(rj.job)
|
||||
|
||||
execContext, err = rj.buildContext(j)
|
||||
if err != nil {
|
||||
buildContextFailed = true
|
||||
goto FAILED //no need to retry
|
||||
}
|
||||
|
||||
defer func() {
|
||||
//Close open io stream first
|
||||
if closer, ok := execContext.GetLogger().(logger.Closer); ok {
|
||||
closer.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
//Start to run
|
||||
rj.jobRunning(j.ID)
|
||||
//Inject data
|
||||
|
Loading…
Reference in New Issue
Block a user