mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-22 00:16:29 +00:00
logs table migration: skip on corrupted json and fail later (#1856)
enhance #1828
This commit is contained in:
parent
ff01a9ff1d
commit
6be61e6c9a
1 changed files with 12 additions and 2 deletions
|
@ -97,9 +97,13 @@ var migrateLogs2LogEntries = task{
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasJSONErrors := false
|
||||||
|
|
||||||
page := 0
|
page := 0
|
||||||
|
offset := 0
|
||||||
logs := make([]*oldLogs019, 0, perPage019)
|
logs := make([]*oldLogs019, 0, perPage019)
|
||||||
logEntries := make([]*oldLogEntry019, 0, 50)
|
logEntries := make([]*oldLogEntry019, 0, 50)
|
||||||
|
|
||||||
sigterm := abool.New()
|
sigterm := abool.New()
|
||||||
ctx, cancelCtx := context.WithCancelCause(context.Background())
|
ctx, cancelCtx := context.WithCancelCause(context.Background())
|
||||||
defer cancelCtx(nil)
|
defer cancelCtx(nil)
|
||||||
|
@ -120,7 +124,7 @@ var migrateLogs2LogEntries = task{
|
||||||
}
|
}
|
||||||
logs = logs[:0]
|
logs = logs[:0]
|
||||||
|
|
||||||
err := sess.Limit(perPage019).Find(&logs)
|
err := sess.Limit(perPage019, offset).Find(&logs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -130,7 +134,9 @@ var migrateLogs2LogEntries = task{
|
||||||
for _, l := range logs {
|
for _, l := range logs {
|
||||||
logEntries = logEntries[:0]
|
logEntries = logEntries[:0]
|
||||||
if err := json.Unmarshal(l.Data, &logEntries); err != nil {
|
if err := json.Unmarshal(l.Data, &logEntries); err != nil {
|
||||||
return err
|
hasJSONErrors = true
|
||||||
|
offset++
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
time := int64(0)
|
time := int64(0)
|
||||||
|
@ -170,6 +176,10 @@ var migrateLogs2LogEntries = task{
|
||||||
page++
|
page++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if hasJSONErrors {
|
||||||
|
return fmt.Errorf("skipped some logs as json could not be deserialized for them")
|
||||||
|
}
|
||||||
|
|
||||||
return e.DropTables("logs")
|
return e.DropTables("logs")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue