Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Job Queues
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Libraries
Go
Services
Job Queues
Commits
ce13f3fc
Verified
Commit
ce13f3fc
authored
1 year ago
by
Volker Schukai
Browse files
Options
Downloads
Patches
Plain Diff
feat: add pause to persistence
#17
parent
e0d03ed3
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
errors.go
+1
-0
1 addition, 0 deletions
errors.go
job.go
+12
-5
12 additions, 5 deletions
job.go
persistence.go
+23
-2
23 additions, 2 deletions
persistence.go
with
36 additions
and
7 deletions
errors.go
+
1
−
0
View file @
ce13f3fc
...
...
@@ -43,4 +43,5 @@ var (
ErrChannelAlreadyClosed
=
fmt
.
Errorf
(
"channel is already closed"
)
ErrUnknownScheduleType
=
fmt
.
Errorf
(
"unknown schedule type"
)
ErrNoManager
=
fmt
.
Errorf
(
"no manager"
)
ErrCannotLoadStatsFromDatabase
=
fmt
.
Errorf
(
"errors while loading stats from database"
)
)
This diff is collapsed.
Click to expand it.
job.go
+
12
−
5
View file @
ce13f3fc
...
...
@@ -27,6 +27,7 @@ const (
// Job is a job that can be executed
type
Job
[
T
any
]
struct
{
id
JobID
description
string
priority
Priority
timeout
time
.
Duration
...
...
@@ -36,6 +37,7 @@ type Job[T any] struct {
scheduler
Scheduler
pause
bool
pauseReason
string
pauseUntil
time
.
Time
dependencies
[]
JobID
...
...
@@ -87,6 +89,7 @@ func (j *Job[T]) GetPersistence() JobPersistence {
job
:=
JobPersistence
{
ID
:
j
.
id
,
Description
:
j
.
description
,
Priority
:
j
.
priority
,
Timeout
:
j
.
timeout
,
MaxRetries
:
j
.
maxRetries
,
...
...
@@ -94,6 +97,10 @@ func (j *Job[T]) GetPersistence() JobPersistence {
Dependencies
:
j
.
dependencies
,
Runnable
:
j
.
runner
.
GetPersistence
(),
Pause
:
j
.
pause
,
PauseReason
:
j
.
pauseReason
,
PauseUntil
:
j
.
pauseUntil
,
Logs
:
j
.
logs
,
Stats
:
j
.
stats
,
}
...
...
This diff is collapsed.
Click to expand it.
persistence.go
+
23
−
2
View file @
ce13f3fc
...
...
@@ -13,6 +13,7 @@ import (
type
JobPersistence
struct
{
ID
JobID
`yaml:"id" json:"id" gorm:"type:varchar(255);primaryKey"`
Description
string
`yaml:"description" json:"description" gorm:"column:description"`
Priority
Priority
`yaml:"priority" json:"priority" gorm:"column:priority"`
Timeout
time
.
Duration
`yaml:"timeout" json:"timeout" gorm:"column:timeout"`
MaxRetries
uint
`yaml:"maxRetries" json:"maxRetries" gorm:"column:max_retries"`
...
...
@@ -21,6 +22,10 @@ type JobPersistence struct {
Runnable
RunnableImport
`yaml:"runnable" json:"runnable" gorm:"embedded;embeddedPrefix:runnable_"`
Scheduler
SchedulerPersistence
`yaml:"scheduler" json:"scheduler,omitempty" gorm:"embedded;embeddedPrefix:scheduler_"`
Pause
bool
`yaml:"pause" json:"pause" gorm:"column:pause"`
PauseReason
string
`yaml:"pauseReason" json:"pauseReason" gorm:"column:pause_reason"`
PauseUntil
time
.
Time
`yaml:"pauseUntil" json:"pauseUntil" gorm:"column:pause_until"`
Logs
[]
JobLog
`gorm:"foreignKey:JobID;references:ID" json:"-" yaml:"-"`
Stats
JobStats
`gorm:"foreignKey:JobID" json:"stats" yaml:"stats"`
...
...
@@ -45,6 +50,18 @@ func (jp JobPersistence) GetPersistence() JobPersistence {
return
jp
}
func
(
jp
JobPersistence
)
GetDescription
()
string
{
return
jp
.
Description
}
func
(
jp
JobPersistence
)
GetPriority
()
Priority
{
return
jp
.
Priority
}
func
(
jp
JobPersistence
)
GetTimeout
()
time
.
Duration
{
return
jp
.
Timeout
}
func
(
JobPersistence
)
TableName
()
string
{
return
globalTableNamePrefix
+
"jobs"
}
...
...
@@ -102,7 +119,7 @@ func ReadFromGORM(db *gorm.DB) ([]JobPersistence, error) {
}
var
wrappedErr
[]
error
// load stats too
for
i
:=
range
jobs
{
if
err
:=
tx
.
Model
(
&
jobs
[
i
])
.
Association
(
"Stats"
)
.
Find
(
&
jobs
[
i
]
.
Stats
);
err
!=
nil
{
wrappedErr
=
append
(
wrappedErr
,
err
)
...
...
@@ -110,7 +127,7 @@ func ReadFromGORM(db *gorm.DB) ([]JobPersistence, error) {
}
if
len
(
wrappedErr
)
>
0
{
returnErr
:=
fmt
.
Errorf
(
"errors while loading s
tats
f
rom
d
atabase
"
)
returnErr
:=
ErrCannotLoadS
tats
F
rom
D
atabase
for
_
,
err
:=
range
wrappedErr
{
returnErr
=
fmt
.
Errorf
(
"%w: %v"
,
returnErr
,
err
)
}
...
...
@@ -126,11 +143,15 @@ func ReadFromGORM(db *gorm.DB) ([]JobPersistence, error) {
func
CreateGenericJobFromPersistence
[
T
any
](
jobImport
JobPersistence
,
runner
Runnable
[
T
])
GenericJob
{
return
&
Job
[
T
]{
id
:
jobImport
.
ID
,
description
:
jobImport
.
Description
,
priority
:
jobImport
.
Priority
,
timeout
:
jobImport
.
Timeout
,
maxRetries
:
jobImport
.
MaxRetries
,
RetryDelay
:
jobImport
.
RetryDelay
,
dependencies
:
jobImport
.
Dependencies
,
pause
:
jobImport
.
Pause
,
pauseReason
:
jobImport
.
PauseReason
,
pauseUntil
:
jobImport
.
PauseUntil
,
runner
:
runner
,
stats
:
jobImport
.
Stats
,
logs
:
jobImport
.
Logs
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment