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
9d774f0a
Verified
Commit
9d774f0a
authored
1 year ago
by
Volker Schukai
Browse files
Options
Downloads
Patches
Plain Diff
feat: new runJob method
#32
parent
5e6046be
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
job-log.go
+11
-11
11 additions, 11 deletions
job-log.go
job-stat.go
+7
-7
7 additions, 7 deletions
job-stat.go
manager.go
+18
-0
18 additions, 0 deletions
manager.go
persistence.go
+2
-2
2 additions, 2 deletions
persistence.go
with
38 additions
and
20 deletions
job-log.go
+
11
−
11
View file @
9d774f0a
...
@@ -6,20 +6,20 @@ import (
...
@@ -6,20 +6,20 @@ import (
)
)
type
JobLog
struct
{
type
JobLog
struct
{
LogID
uint
`gorm:"primarykey;autoIncrement:true" json:"log
_i
d"`
LogID
uint
`gorm:"primarykey;autoIncrement:true" json:"log
I
d"`
JobID
JobID
`json:"job
_i
d" gorm:"type:varchar(255);foreignKey:JobID;references:ID"`
JobID
JobID
`json:"job
I
d" gorm:"type:varchar(255);foreignKey:JobID;references:ID"`
ProcessID
int
`json:"process
_i
d"`
ProcessID
int
`json:"process
I
d"`
StartTime
time
.
Time
`json:"start
_t
ime"`
StartTime
time
.
Time
`json:"start
T
ime"`
EndTime
time
.
Time
`json:"end
_t
ime"`
EndTime
time
.
Time
`json:"end
T
ime"`
ExitCode
int
`json:"exit
_c
ode"`
ExitCode
int
`json:"exit
C
ode"`
Result
string
`json:"output" gorm:"type:TEXT"`
// Assuming serialized JSON for any type
Result
string
`json:"output" gorm:"type:TEXT"`
// Assuming serialized JSON for any type
ResourceUsage
ResourceUsage
`json:"resource
_u
sage" gorm:"embedded;embeddedPrefix:resource_usage_"`
ResourceUsage
ResourceUsage
`json:"resource
U
sage" gorm:"embedded;embeddedPrefix:resource_usage_"`
IO
IO
`json:"io" gorm:"embedded;embeddedPrefix:io_"`
IO
IO
`json:"io" gorm:"embedded;embeddedPrefix:io_"`
ErrorMsg
string
`json:"error
_m
sg"`
ErrorMsg
string
`json:"error
M
sg"`
IsSuccessful
bool
`json:"is
_s
uccessful"`
IsSuccessful
bool
`json:"is
S
uccessful"`
CreatedAt
time
.
Time
`gorm:"column:created_at" json:"created
_a
t" yaml:"created
_a
t"`
CreatedAt
time
.
Time
`gorm:"column:created_at" json:"created
A
t" yaml:"created
A
t"`
UpdatedAt
time
.
Time
`gorm:"column:updated_at" json:"updated
_a
t" yaml:"updated
_a
t"`
UpdatedAt
time
.
Time
`gorm:"column:updated_at" json:"updated
A
t" yaml:"updated
A
t"`
DeletedAt
gorm
.
DeletedAt
`gorm:"column:deleted_at;index" json:"-" yaml:"-"`
DeletedAt
gorm
.
DeletedAt
`gorm:"column:deleted_at;index" json:"-" yaml:"-"`
}
}
...
...
This diff is collapsed.
Click to expand it.
job-stat.go
+
7
−
7
View file @
9d774f0a
...
@@ -7,14 +7,14 @@ import (
...
@@ -7,14 +7,14 @@ import (
// important: if you want to add fields to this struct, you have to add them to the ResetStats() method as well
// important: if you want to add fields to this struct, you have to add them to the ResetStats() method as well
type
JobStats
struct
{
type
JobStats
struct
{
JobID
JobID
`json:"job
_i
d" gorm:"primaryKey"`
JobID
JobID
`json:"job
I
d" gorm:"primaryKey"`
RunCount
int
`json:"run
_c
ount"`
RunCount
int
`json:"run
C
ount"`
SuccessCount
int
`json:"success
_c
ount"`
SuccessCount
int
`json:"success
C
ount"`
ErrorCount
int
`json:"error
_c
ount"`
ErrorCount
int
`json:"error
C
ount"`
TimeMetrics
TimeMetrics
`json:"time
_m
etrics" gorm:"embedded;embeddedPrefix:time_metrics_"`
TimeMetrics
TimeMetrics
`json:"time
M
etrics" gorm:"embedded;embeddedPrefix:time_metrics_"`
CreatedAt
time
.
Time
`gorm:"column:created_at" json:"created
_a
t" yaml:"created
_a
t"`
CreatedAt
time
.
Time
`gorm:"column:created_at" json:"created
A
t" yaml:"created
A
t"`
UpdatedAt
time
.
Time
`gorm:"column:updated_at" json:"updated
_a
t" yaml:"updated
_a
t"`
UpdatedAt
time
.
Time
`gorm:"column:updated_at" json:"updated
A
t" yaml:"updated
A
t"`
DeletedAt
gorm
.
DeletedAt
`gorm:"column:deleted_at;index" json:"-" yaml:"-"`
DeletedAt
gorm
.
DeletedAt
`gorm:"column:deleted_at;index" json:"-" yaml:"-"`
}
}
...
...
This diff is collapsed.
Click to expand it.
manager.go
+
18
−
0
View file @
9d774f0a
...
@@ -481,12 +481,30 @@ func (m *Manager) SetLogger(logger Logger) *Manager {
...
@@ -481,12 +481,30 @@ func (m *Manager) SetLogger(logger Logger) *Manager {
return
m
return
m
}
}
// GetLogger returns the logger
func
(
m
*
Manager
)
GetLogger
()
Logger
{
func
(
m
*
Manager
)
GetLogger
()
Logger
{
m
.
mu
.
Lock
()
m
.
mu
.
Lock
()
defer
m
.
mu
.
Unlock
()
defer
m
.
mu
.
Unlock
()
return
m
.
logger
return
m
.
logger
}
}
// RunJob runs a job immediately and does not schedule it
func
(
m
*
Manager
)
RunJob
(
job
GenericJob
)
error
{
m
.
mu
.
Lock
()
defer
m
.
mu
.
Unlock
()
if
m
.
state
!=
ManagerStateRunning
{
return
ErrManagerNotRunning
}
if
!
job
.
IsPaused
()
{
m
.
eventBus
.
Publish
(
QueueJob
,
job
)
}
return
nil
}
// ScheduleJob schedules a job
// ScheduleJob schedules a job
func
(
m
*
Manager
)
ScheduleJob
(
job
GenericJob
,
scheduler
Scheduler
)
error
{
func
(
m
*
Manager
)
ScheduleJob
(
job
GenericJob
,
scheduler
Scheduler
)
error
{
m
.
mu
.
Lock
()
m
.
mu
.
Lock
()
...
...
This diff is collapsed.
Click to expand it.
persistence.go
+
2
−
2
View file @
9d774f0a
...
@@ -30,8 +30,8 @@ type JobPersistence struct {
...
@@ -30,8 +30,8 @@ type JobPersistence struct {
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:"created
_a
t" yaml:"created
_a
t"`
CreatedAt
time
.
Time
`gorm:"column:created_at" json:"created
A
t" yaml:"created
A
t"`
UpdatedAt
time
.
Time
`gorm:"column:updated_at" json:"updated
_a
t" yaml:"updated
_a
t"`
UpdatedAt
time
.
Time
`gorm:"column:updated_at" json:"updated
A
t" yaml:"updated
A
t"`
DeletedAt
gorm
.
DeletedAt
`gorm:"column:deleted_at;index" json:"-" yaml:"-"`
DeletedAt
gorm
.
DeletedAt
`gorm:"column:deleted_at;index" json:"-" yaml:"-"`
}
}
...
...
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