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
db62cbb4
Verified
Commit
db62cbb4
authored
1 year ago
by
Volker Schukai
Browse files
Options
Downloads
Patches
Plain Diff
fix: save all stats
#51
parent
d2965f23
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
database-4_test.go
+6
-5
6 additions, 5 deletions
database-4_test.go
database.go
+18
-6
18 additions, 6 deletions
database.go
event-bus.go
+1
-0
1 addition, 0 deletions
event-bus.go
with
25 additions
and
11 deletions
database-4_test.go
+
6
−
5
View file @
db62cbb4
...
...
@@ -13,8 +13,9 @@ import (
func
TestWriteToDB4
(
t
*
testing
.
T
)
{
db
,
err
:=
gorm
.
Open
(
sqlite
.
Open
(
"file::memory:?cache=shared"
),
&
gorm
.
Config
{})
//db, err := gorm.Open(sqlite.Open("file:/home/vs/workspaces/alvine/cloud/framework/dummy.sqlite"), &gorm.Config{})
if
err
!=
nil
{
t
.
Fatalf
(
"a error occurred while opening the database: %v"
,
err
)
t
.
Fatalf
(
"a
n
error occurred while opening the database: %v"
,
err
)
}
manager
:=
NewManager
()
...
...
@@ -45,13 +46,13 @@ func TestWriteToDB4(t *testing.T) {
err
=
manager
.
ScheduleJob
(
job
,
scheduler
)
assert
.
Nil
(
t
,
err
)
time
.
Sleep
(
200
*
time
.
Millisecond
)
assert
.
Equal
(
t
,
21
,
job
.
GetStats
()
.
RunCount
)
time
.
Sleep
(
100
*
time
.
Millisecond
)
Info
(
"WaitSync"
)
manager
.
WaitSync
()
assert
.
Equal
(
t
,
21
,
job
.
GetStats
()
.
RunCount
)
// check
is
stats are the values above
// check
the
stats are the values above
var
tmpJob
JobPersistence
err
=
db
.
Preload
(
"Stats"
)
.
First
(
&
tmpJob
,
"id = ?"
,
"job3"
)
.
Error
...
...
This diff is collapsed.
Click to expand it.
database.go
+
18
−
6
View file @
db62cbb4
...
...
@@ -88,7 +88,7 @@ func (s *JobSyncer) ResetStats(job GenericJob) error {
if
s
.
manager
==
nil
||
s
.
manager
.
database
==
nil
{
return
ErrNoDatabaseConnection
}
return
sav
eJob
(
job
,
s
.
manager
.
database
)
return
updat
eJob
(
job
,
s
.
manager
.
database
)
}
...
...
@@ -137,13 +137,20 @@ func update(job *JobPersistence, db *gorm.DB) error {
return
ErrNoDatabaseConnection
}
permJob
:=
job
.
GetPersistence
()
return
db
.
Transaction
(
func
(
tx
*
gorm
.
DB
)
error
{
if
permJob
.
Stats
!=
(
JobStats
{})
{
if
err
:=
tx
.
Model
(
&
permJob
)
.
Select
(
"Stats"
)
.
Updates
(
map
[
string
]
interface
{}{
"stats"
:
permJob
.
Stats
})
.
Error
;
err
!=
nil
{
return
err
if
job
.
Stats
!=
(
JobStats
{})
{
Info
(
"Updating stats for job %s"
,
job
.
ID
)
if
job
.
Stats
.
RunCount
==
0
{
Info
(
"Stats runCount is 0, skipping update"
)
}
if
err
:=
tx
.
Model
(
job
.
Stats
)
.
Select
(
"*"
)
.
Omit
(
"job_id"
,
"created_at"
)
.
Updates
(
job
.
Stats
)
.
Error
;
err
!=
nil
{
return
err
// Fehler beim Update
}
}
...
...
@@ -180,6 +187,11 @@ func save(job *JobPersistence, db *gorm.DB) error {
if
job
.
Stats
!=
(
JobStats
{})
{
job
.
Stats
.
JobID
=
job
.
ID
if
job
.
Stats
.
RunCount
==
0
{
Info
(
"Stats runCount is 0, skipping update"
)
}
if
err
:=
tx
.
Save
(
&
job
.
Stats
)
.
Error
;
err
!=
nil
{
return
err
}
...
...
This diff is collapsed.
Click to expand it.
event-bus.go
+
1
−
0
View file @
db62cbb4
...
...
@@ -132,6 +132,7 @@ func (eb *EventBus) Publish(name EventName, data any) {
defer
func
()
{
if
r
:=
recover
();
r
!=
nil
{
Error
(
"EventBus: publish panic: %v"
,
r
)
eb
.
SetPublishError
(
msgID
,
fmt
.
Errorf
(
"publish panic: %v"
,
r
))
}
}()
...
...
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