Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • oss/libraries/go/services/job-queues
1 result
Select Git revision
Show changes
Commits on Source (1)
Showing
with 25 additions and 18 deletions
......@@ -17,8 +17,9 @@ func (id JobID) String() string {
return string(id)
}
type GetResult interface {
type GetResultAndError interface {
GetResult() string
GetError() (string, int)
}
// Priority is the priority of a job
......@@ -206,6 +207,11 @@ func (j *Job[T]) Execute(ctx context.Context) (RunGenericResult, error) {
endTime := time.Now()
elapsedTime := endTime.Sub(startTime)
isSuccessful := runnerError == nil
if r.Status != ResultStatusSuccess {
isSuccessful = false
}
j.mu.Lock()
defer j.mu.Unlock()
......@@ -235,8 +241,7 @@ func (j *Job[T]) Execute(ctx context.Context) (RunGenericResult, error) {
j.stats.TimeMetrics.AvgRunTime = j.stats.TimeMetrics.TotalRunTime / time.Duration(j.stats.RunCount)
}
// Update SuccessCount or ErrorCount and codes
if runnerError == nil {
if isSuccessful {
j.stats.SuccessCount++
} else {
j.stats.ErrorCount++
......@@ -246,13 +251,23 @@ func (j *Job[T]) Execute(ctx context.Context) (RunGenericResult, error) {
StartTime: startTime,
}
if runnerError == nil {
if isSuccessful {
newLog.IsSuccessful = true
newLog.ExitCode = 0
} else {
switch v := any(r.Data).(type) {
case GetResultAndError:
newLog.ErrorMsg, newLog.ExitCode = v.GetError()
}
if newLog.ErrorMsg == "" {
newLog.ErrorMsg = runnerError.Error()
}
newLog.IsSuccessful = false
newLog.ExitCode = 1 // Set to appropriate error code if applicable
newLog.ErrorMsg = runnerError.Error()
if newLog.ExitCode == 0 {
newLog.ExitCode = DefaultErrorExitCode
}
}
newLog.StartTime = startTime
......@@ -260,11 +275,11 @@ func (j *Job[T]) Execute(ctx context.Context) (RunGenericResult, error) {
newLog.ProcessID = os.Getpid() // Assuming you want the PID of the current process
newLog.EndTime = time.Now()
if runnerError != nil {
newLog.ErrorMsg = runnerError.Error()
}
newLog.Result = CheckAndCallGetResult(&r.Data)
switch v := any(r.Data).(type) {
case GetResultAndError:
newLog.Result = v.GetResult()
}
j.logs = append(j.logs, newLog)
......@@ -272,14 +287,6 @@ func (j *Job[T]) Execute(ctx context.Context) (RunGenericResult, error) {
return genericResult, runnerError
}
func CheckAndCallGetResult[T any](data T) string {
switch v := any(data).(type) {
case GetResult:
return v.GetResult()
}
return ""
}
// Cancel cancels the job, currently a no-op
func (j *Job[T]) Cancel() error {
return nil
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755