Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added lastUpdateErrorLock to work units. #755

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions pkg/workceptor/workunitbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,17 @@ func IsPending(err error) bool {

// BaseWorkUnit includes data common to all work units, and partially implements the WorkUnit interface.
type BaseWorkUnit struct {
w *Workceptor
status StatusFileData
unitID string
unitDir string
statusFileName string
stdoutFileName string
statusLock *sync.RWMutex
lastUpdateError error
ctx context.Context
cancel context.CancelFunc
w *Workceptor
status StatusFileData
unitID string
unitDir string
statusFileName string
stdoutFileName string
statusLock *sync.RWMutex
lastUpdateError error
lastUpdateErrorLock *sync.RWMutex
ctx context.Context
cancel context.CancelFunc
}

// Init initializes the basic work unit data, in memory only.
Expand All @@ -86,6 +87,7 @@ func (bwu *BaseWorkUnit) Init(w *Workceptor, unitID string, workType string) {
bwu.statusFileName = path.Join(bwu.unitDir, "status")
bwu.stdoutFileName = path.Join(bwu.unitDir, "stdout")
bwu.statusLock = &sync.RWMutex{}
bwu.lastUpdateErrorLock = &sync.RWMutex{}
bwu.ctx, bwu.cancel = context.WithCancel(w.ctx)
}

Expand Down Expand Up @@ -291,6 +293,8 @@ func (bwu *BaseWorkUnit) UpdateFullStatus(statusFunc func(*StatusFileData)) {
bwu.statusLock.Lock()
defer bwu.statusLock.Unlock()
err := bwu.status.UpdateFullStatus(bwu.statusFileName, statusFunc)
bwu.lastUpdateErrorLock.Lock()
defer bwu.lastUpdateErrorLock.Unlock()
bwu.lastUpdateError = err
if err != nil {
bwu.w.nc.Logger.Error("Error updating status file %s: %s.", bwu.statusFileName, err)
Expand All @@ -315,6 +319,8 @@ func (bwu *BaseWorkUnit) UpdateBasicStatus(state int, detail string, stdoutSize
bwu.statusLock.Lock()
defer bwu.statusLock.Unlock()
err := bwu.status.UpdateBasicStatus(bwu.statusFileName, state, detail, stdoutSize)
bwu.lastUpdateErrorLock.Lock()
defer bwu.lastUpdateErrorLock.Unlock()
bwu.lastUpdateError = err
if err != nil {
bwu.w.nc.Logger.Error("Error updating status file %s: %s.", bwu.statusFileName, err)
Expand All @@ -323,6 +329,9 @@ func (bwu *BaseWorkUnit) UpdateBasicStatus(state int, detail string, stdoutSize

// LastUpdateError returns the last error (including nil) resulting from an UpdateBasicStatus or UpdateFullStatus.
func (bwu *BaseWorkUnit) LastUpdateError() error {
bwu.lastUpdateErrorLock.Lock()
defer bwu.lastUpdateErrorLock.Unlock()

return bwu.lastUpdateError
}

Expand Down