-
Notifications
You must be signed in to change notification settings - Fork 88
/
app.go
67 lines (57 loc) · 1.9 KB
/
app.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package app
import (
"fmt"
"time"
"github.com/replicatedhq/kots/pkg/app/types"
"github.com/replicatedhq/kots/pkg/persistence"
"github.com/rqlite/gorqlite"
)
// SetLastUpdateAtTime sets the time that the client last checked for an update to now
func SetLastUpdateAtTime(appID string, t time.Time) error {
db := persistence.MustGetDBSession()
query := `update app set last_update_check_at = ? where id = ?`
wr, err := db.WriteOneParameterized(gorqlite.ParameterizedStatement{
Query: query,
Arguments: []interface{}{t.Unix(), appID},
})
if err != nil {
return fmt.Errorf("failed to update last_update_check_at: %v: %v", err, wr.Err)
}
return nil
}
func InitiateRestore(snapshotName string, appID string) error {
db := persistence.MustGetDBSession()
query := `update app set restore_in_progress_name = ? where id = ?`
wr, err := db.WriteOneParameterized(gorqlite.ParameterizedStatement{
Query: query,
Arguments: []interface{}{snapshotName, appID},
})
if err != nil {
return fmt.Errorf("failed to update restore_in_progress_name: %v: %v", err, wr.Err)
}
return nil
}
func ResetRestore(appID string) error {
db := persistence.MustGetDBSession()
query := `update app set restore_in_progress_name = NULL, restore_undeploy_status = '' where id = ?`
wr, err := db.WriteOneParameterized(gorqlite.ParameterizedStatement{
Query: query,
Arguments: []interface{}{appID},
})
if err != nil {
return fmt.Errorf("failed to write: %v: %v", err, wr.Err)
}
return nil
}
func SetRestoreUndeployStatus(appID string, undeployStatus types.UndeployStatus) error {
db := persistence.MustGetDBSession()
query := `update app set restore_undeploy_status = ? where id = ?`
wr, err := db.WriteOneParameterized(gorqlite.ParameterizedStatement{
Query: query,
Arguments: []interface{}{undeployStatus, appID},
})
if err != nil {
return fmt.Errorf("failed to write: %v: %v", err, wr.Err)
}
return nil
}