-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcache_index.go
More file actions
61 lines (50 loc) · 1.3 KB
/
cache_index.go
File metadata and controls
61 lines (50 loc) · 1.3 KB
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
package main
import (
"context"
"time"
"github.com/urfave/cli"
services "github.com/webtor-io/common-services"
ci "github.com/webtor-io/web-ui/services/cache_index"
log "github.com/sirupsen/logrus"
)
func makeCacheIndexCMD() cli.Command {
cacheIndexCmd := cli.Command{
Name: "cache-index",
Aliases: []string{"ci"},
Usage: "Cache index operations",
}
configureCacheIndex(&cacheIndexCmd)
return cacheIndexCmd
}
func configureCacheIndex(c *cli.Command) {
cleanupCmd := cli.Command{
Name: "cleanup",
Usage: "Cleans up old cache index entries",
Aliases: []string{"c"},
Action: func(c *cli.Context) error {
return cacheIndexCleanup(c)
},
}
c.Subcommands = []cli.Command{cleanupCmd}
for k, _ := range c.Subcommands {
configureSubCacheIndex(&c.Subcommands[k])
}
}
func configureSubCacheIndex(c *cli.Command) {
c.Flags = services.RegisterPGFlags(c.Flags)
c.Flags = ci.RegisterFlags(c.Flags)
}
func cacheIndexCleanup(c *cli.Context) error {
// Setting DB
pg := services.NewPG(c)
defer pg.Close()
// Setting CacheIndex
cacheIndex := ci.New(c, pg)
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()
// Run cleanup
log.Info("running cache index cleanup")
cacheIndex.RunCleanup(ctx)
log.Info("cache index cleanup completed")
return nil
}