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
  • master
  • v1.0.0
  • v1.0.1
  • v1.1.0
  • v1.10.0
  • v1.10.1
  • v1.10.2
  • v1.11.0
  • v1.12.0
  • v1.12.1
  • v1.12.2
  • v1.12.3
  • v1.12.4
  • v1.12.5
  • v1.12.6
  • v1.12.7
  • v1.12.8
  • v1.13.0
  • v1.13.1
  • v1.13.2
  • v1.14.0
  • v1.15.0
  • v1.15.1
  • v1.15.10
  • v1.15.11
  • v1.15.12
  • v1.15.13
  • v1.15.14
  • v1.15.15
  • v1.15.16
  • v1.15.17
  • v1.15.2
  • v1.15.3
  • v1.15.4
  • v1.15.5
  • v1.15.6
  • v1.15.7
  • v1.15.8
  • v1.15.9
  • v1.16.0
  • v1.16.1
  • v1.17.0
  • v1.18.0
  • v1.18.1
  • v1.18.2
  • v1.19.0
  • v1.19.1
  • v1.19.2
  • v1.19.3
  • v1.19.4
  • v1.2.0
  • v1.20.0
  • v1.20.1
  • v1.20.2
  • v1.20.3
  • v1.21.0
  • v1.21.1
  • v1.22.0
  • v1.23.0
  • v1.23.1
  • v1.23.2
  • v1.3.0
  • v1.3.1
  • v1.3.2
  • v1.4.0
  • v1.5.0
  • v1.5.1
  • v1.6.0
  • v1.6.1
  • v1.7.0
  • v1.7.1
  • v1.7.2
  • v1.7.3
  • v1.8.0
  • v1.8.1
  • v1.9.0
76 results

Target

Select target project
  • oss/libraries/go/services/job-queues
1 result
Select Git revision
  • master
  • v1.0.0
  • v1.0.1
  • v1.1.0
  • v1.10.0
  • v1.10.1
  • v1.10.2
  • v1.11.0
  • v1.12.0
  • v1.12.1
  • v1.12.2
  • v1.12.3
  • v1.12.4
  • v1.12.5
  • v1.12.6
  • v1.12.7
  • v1.12.8
  • v1.13.0
  • v1.13.1
  • v1.13.2
  • v1.14.0
  • v1.15.0
  • v1.15.1
  • v1.15.10
  • v1.15.11
  • v1.15.12
  • v1.15.13
  • v1.15.14
  • v1.15.15
  • v1.15.16
  • v1.15.17
  • v1.15.2
  • v1.15.3
  • v1.15.4
  • v1.15.5
  • v1.15.6
  • v1.15.7
  • v1.15.8
  • v1.15.9
  • v1.16.0
  • v1.16.1
  • v1.17.0
  • v1.18.0
  • v1.18.1
  • v1.18.2
  • v1.19.0
  • v1.19.1
  • v1.19.2
  • v1.19.3
  • v1.19.4
  • v1.2.0
  • v1.20.0
  • v1.20.1
  • v1.20.2
  • v1.20.3
  • v1.21.0
  • v1.21.1
  • v1.22.0
  • v1.23.0
  • v1.23.1
  • v1.23.2
  • v1.3.0
  • v1.3.1
  • v1.3.2
  • v1.4.0
  • v1.5.0
  • v1.5.1
  • v1.6.0
  • v1.6.1
  • v1.7.0
  • v1.7.1
  • v1.7.2
  • v1.7.3
  • v1.8.0
  • v1.8.1
  • v1.9.0
76 results
Show changes
Commits on Source (1)
...@@ -40,7 +40,7 @@ func TestWriteToDB4(t *testing.T) { ...@@ -40,7 +40,7 @@ func TestWriteToDB4(t *testing.T) {
id := job.GetID() id := job.GetID()
job.mu.Lock() job.mu.Lock()
job.stats = JobStats{ job.stats = &JobStats{
JobID: id, JobID: id,
RunCount: 20, RunCount: 20,
SuccessCount: 30, SuccessCount: 30,
......
...@@ -86,7 +86,7 @@ func TestCheckAndSaveOrUpdate(t *testing.T) { ...@@ -86,7 +86,7 @@ func TestCheckAndSaveOrUpdate(t *testing.T) {
assert.Equal(t, PriorityDefault, jobPersistence.Priority) // second update should not update the priority, because update only update stats and logs assert.Equal(t, PriorityDefault, jobPersistence.Priority) // second update should not update the priority, because update only update stats and logs
// set stats and logs and test // set stats and logs and test
job.stats = JobStats{ job.stats = &JobStats{
JobID: job.GetID(), JobID: job.GetID(),
RunCount: 2, RunCount: 2,
SuccessCount: 3, SuccessCount: 3,
......
...@@ -135,7 +135,7 @@ func update(job *JobPersistence, db *gorm.DB) error { ...@@ -135,7 +135,7 @@ func update(job *JobPersistence, db *gorm.DB) error {
return db.Transaction(func(tx *gorm.DB) error { return db.Transaction(func(tx *gorm.DB) error {
if job.Stats != (JobStats{}) { if job.Stats != nil {
Info("Updating stats for job %s", job.ID) Info("Updating stats for job %s", job.ID)
if job.Stats.RunCount == 0 { if job.Stats.RunCount == 0 {
...@@ -192,7 +192,7 @@ func save(job *JobPersistence, db *gorm.DB) error { ...@@ -192,7 +192,7 @@ func save(job *JobPersistence, db *gorm.DB) error {
} }
} }
if job.Stats != (JobStats{}) { if job.Stats != nil {
job.Stats.JobID = job.ID job.Stats.JobID = job.ID
if err := tx.Model(job.Stats). if err := tx.Model(job.Stats).
......
...@@ -54,7 +54,7 @@ type Job[T any] struct { ...@@ -54,7 +54,7 @@ type Job[T any] struct {
runner Runnable[T] runner Runnable[T]
stats JobStats stats *JobStats
logs []JobLog logs []JobLog
} }
...@@ -65,7 +65,7 @@ func NewJob[T any](id JobID, runner Runnable[T]) *Job[T] { ...@@ -65,7 +65,7 @@ func NewJob[T any](id JobID, runner Runnable[T]) *Job[T] {
runner: runner, runner: runner,
priority: PriorityDefault, priority: PriorityDefault,
logs: make([]JobLog, 0), logs: make([]JobLog, 0),
stats: JobStats{}, stats: &JobStats{},
} }
} }
...@@ -84,7 +84,7 @@ func (j *Job[T]) GetStats() JobStats { ...@@ -84,7 +84,7 @@ func (j *Job[T]) GetStats() JobStats {
defer j.mu.Unlock() defer j.mu.Unlock()
// workaround for gorm // workaround for gorm
j.stats.JobID = j.id j.stats.JobID = j.id
return j.stats return *j.stats
} }
// GetPersistence returns the persistence of the job // GetPersistence returns the persistence of the job
...@@ -165,7 +165,7 @@ func (j *Job[T]) Resume() { ...@@ -165,7 +165,7 @@ func (j *Job[T]) Resume() {
func (j *Job[T]) ResetStats() { func (j *Job[T]) ResetStats() {
j.mu.Lock() j.mu.Lock()
defer j.mu.Unlock() defer j.mu.Unlock()
j.stats = JobStats{ j.stats = &JobStats{
JobID: j.id, JobID: j.id,
RunCount: 0, RunCount: 0,
SuccessCount: 0, SuccessCount: 0,
...@@ -216,6 +216,12 @@ func (j *Job[T]) Execute(ctx context.Context) (RunGenericResult, error) { ...@@ -216,6 +216,12 @@ func (j *Job[T]) Execute(ctx context.Context) (RunGenericResult, error) {
defer j.mu.Unlock() defer j.mu.Unlock()
// Update RunCount // Update RunCount
if j.stats == nil {
j.stats = &JobStats{
JobID: j.id,
}
}
j.stats.RunCount++ j.stats.RunCount++
// Update TimeMetrics // Update TimeMetrics
......
...@@ -34,8 +34,8 @@ type JobPersistence struct { ...@@ -34,8 +34,8 @@ type JobPersistence struct {
RetryDelayString *string `yaml:"retryDelay,omitempty" json:"retryDelay,omitempty" gorm:"-"` RetryDelayString *string `yaml:"retryDelay,omitempty" json:"retryDelay,omitempty" gorm:"-"`
PauseUntilString *string `yaml:"pauseUntil" json:"pauseUntil,omitempty" gorm:"-"` PauseUntilString *string `yaml:"pauseUntil" json:"pauseUntil,omitempty" gorm:"-"`
Logs []JobLog `gorm:"foreignKey:JobID;references:ID" json:"-" yaml:"-"` Logs []JobLog `gorm:"foreignKey:JobID;references:ID" json:"-" yaml:"-"`
Stats JobStats `gorm:"foreignKey:JobID" json:"stats" yaml:"stats"` Stats *JobStats `gorm:"foreignKey:JobID" json:"stats" yaml:"stats"`
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt" yaml:"createdAt"` CreatedAt time.Time `gorm:"column:created_at" json:"createdAt" yaml:"createdAt"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt" yaml:"updatedAt"` UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt" yaml:"updatedAt"`
...@@ -155,7 +155,7 @@ func (jp JobPersistence) GetLogs() []JobLog { ...@@ -155,7 +155,7 @@ func (jp JobPersistence) GetLogs() []JobLog {
} }
func (jp JobPersistence) GetStats() JobStats { func (jp JobPersistence) GetStats() JobStats {
return jp.Stats return *jp.Stats
} }
func (jp JobPersistence) GetID() JobID { func (jp JobPersistence) GetID() JobID {
......
...@@ -126,6 +126,9 @@ func TestJobPersistence_MarshalUnmarshalJSON(t *testing.T) { ...@@ -126,6 +126,9 @@ func TestJobPersistence_MarshalUnmarshalJSON(t *testing.T) {
TimeoutString: &time5m0sString, TimeoutString: &time5m0sString,
RetryDelayString: &time10sString, RetryDelayString: &time10sString,
PauseUntilString: &timeRefString, PauseUntilString: &timeRefString,
Stats: &JobStats{
JobID: "",
},
}, },
expected: ` {"id":"","description":"","priority":0,"maxRetries":0,"runnable":{"type":""},"scheduler":{"type":""},"pause":false,"pauseReason":"","timeout":"5m0s","retryDelay":"10s","pauseUntil":"` + timeRefString + `","stats":{"jobId":"","runCount":0,"successCount":0,"errorCount":0,"timeMetrics":{"avg":0,"max":0,"min":0,"total":0},"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z"},"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z"}`, expected: ` {"id":"","description":"","priority":0,"maxRetries":0,"runnable":{"type":""},"scheduler":{"type":""},"pause":false,"pauseReason":"","timeout":"5m0s","retryDelay":"10s","pauseUntil":"` + timeRefString + `","stats":{"jobId":"","runCount":0,"successCount":0,"errorCount":0,"timeMetrics":{"avg":0,"max":0,"min":0,"total":0},"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z"},"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z"}`,
}, },
...@@ -139,7 +142,7 @@ func TestJobPersistence_MarshalUnmarshalJSON(t *testing.T) { ...@@ -139,7 +142,7 @@ func TestJobPersistence_MarshalUnmarshalJSON(t *testing.T) {
RetryDelayString: &time30sString, RetryDelayString: &time30sString,
PauseUntilString: &emptyString, PauseUntilString: &emptyString,
}, },
expected: `{"id":"","description":"","priority":0,"maxRetries":0,"runnable":{"type":""},"scheduler":{"type":""},"pause":false,"pauseReason":"","timeout":"1h0m0s","retryDelay":"30s","pauseUntil":"","stats":{"jobId":"","runCount":0,"successCount":0,"errorCount":0,"timeMetrics":{"avg":0,"max":0,"min":0,"total":0},"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z"},"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z"}`, expected: `{"id":"","description":"","priority":0,"maxRetries":0,"runnable":{"type":""},"scheduler":{"type":""},"pause":false,"pauseReason":"","timeout":"1h0m0s","retryDelay":"30s","pauseUntil":"","stats":null,"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z"}`,
}, },
{ {
name: "Nil timeout and retryDelay", name: "Nil timeout and retryDelay",
...@@ -151,7 +154,7 @@ func TestJobPersistence_MarshalUnmarshalJSON(t *testing.T) { ...@@ -151,7 +154,7 @@ func TestJobPersistence_MarshalUnmarshalJSON(t *testing.T) {
RetryDelayString: &emptyString, RetryDelayString: &emptyString,
PauseUntilString: &emptyString, PauseUntilString: &emptyString,
}, },
expected: `{"id":"","description":"","priority":0,"maxRetries":0,"runnable":{"type":""},"scheduler":{"type":""},"pause":false,"pauseReason":"","timeout":"","retryDelay":"","pauseUntil":"","stats":{"jobId":"","runCount":0,"successCount":0,"errorCount":0,"timeMetrics":{"avg":0,"max":0,"min":0,"total":0},"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z"},"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z"}`, expected: `{"id":"","description":"","priority":0,"maxRetries":0,"runnable":{"type":""},"scheduler":{"type":""},"pause":false,"pauseReason":"","timeout":"","retryDelay":"","pauseUntil":"","stats":null,"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z"}`,
}, },
} }
...@@ -159,12 +162,14 @@ func TestJobPersistence_MarshalUnmarshalJSON(t *testing.T) { ...@@ -159,12 +162,14 @@ func TestJobPersistence_MarshalUnmarshalJSON(t *testing.T) {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
// MarshalJSON testen // MarshalJSON testen
data, err := json.Marshal(tc.job) data, err := json.Marshal(tc.job)
//t.Log(string(data))
assert.NoError(t, err) assert.NoError(t, err)
assert.JSONEq(t, tc.expected, string(data)) assert.JSONEq(t, tc.expected, string(data))
var job JobPersistence var job JobPersistence
err = json.Unmarshal(data, &job) err = json.Unmarshal(data, &job)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, tc.job.Timeout, job.Timeout) assert.Equal(t, tc.job.Timeout, job.Timeout)
assert.Equal(t, tc.job.RetryDelay, job.RetryDelay) assert.Equal(t, tc.job.RetryDelay, job.RetryDelay)
......