-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathclean.go
34 lines (26 loc) · 919 Bytes
/
clean.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// SPDX-License-Identifier: Apache-2.0
package service
import (
"context"
"time"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/database"
"github.com/go-vela/types/library"
"github.com/sirupsen/logrus"
)
// CleanServices updates services to an error with a created timestamp prior to a defined moment.
func (e *engine) CleanServices(ctx context.Context, msg string, before int64) (int64, error) {
logrus.Tracef("cleaning pending or running steps in the database created prior to %d", before)
s := new(library.Service)
s.SetStatus(constants.StatusError)
s.SetError(msg)
s.SetFinished(time.Now().UTC().Unix())
service := database.ServiceFromLibrary(s)
// send query to the database
result := e.client.
Table(constants.TableService).
Where("created < ?", before).
Where("status = 'running' OR status = 'pending'").
Updates(service)
return result.RowsAffected, result.Error
}