- commit
- 1cfab57
- parent
- 4bb1cb7
- author
- Antonio Mika
- date
- 2025-04-22 13:33:10 -0400 EDT
Update context logic
2 files changed,
+27,
-8
+2,
-3
1@@ -831,15 +831,14 @@ func StartApiServer() {
2 db := postgres.NewDB(cfg.DbURL, logger)
3 defer db.Close()
4
5- ctx := context.Background()
6+ ctx, cancel := context.WithCancel(context.Background())
7+ defer cancel()
8
9 // gather metrics in the auth service
10 go metricDrainSub(ctx, db, logger, cfg.Secret)
11 // gather connect/disconnect logs from tuns
12 go tunsEventLogDrainSub(ctx, db, logger, cfg.Secret)
13
14- defer ctx.Done()
15-
16 apiConfig := &shared.ApiConfig{
17 Cfg: cfg,
18 Dbpool: db,
+25,
-5
1@@ -14,6 +14,7 @@ import (
2 pgsdb "github.com/picosh/pico/pkg/apps/pgs/db"
3 "github.com/picosh/pico/pkg/db"
4 sst "github.com/picosh/pico/pkg/pobj/storage"
5+ "github.com/picosh/pico/pkg/pssh"
6 "github.com/picosh/pico/pkg/shared"
7 "github.com/picosh/utils"
8 )
9@@ -507,11 +508,22 @@ func (c *Cmd) cache(projectName string) error {
10 "user", c.User.Name,
11 "project", projectName,
12 )
13+
14 c.output(fmt.Sprintf("clearing http cache for %s", projectName))
15- ctx := context.Background()
16- defer ctx.Done()
17- send := createPubCacheDrain(ctx, c.Log)
18+
19 if c.Write {
20+ var ctx context.Context
21+ if s, ok := c.Session.(*pssh.SSHServerConnSession); ok {
22+ ctx = s.Context()
23+ } else {
24+ ctx = context.Background()
25+ }
26+
27+ ctx, cancel := context.WithCancel(ctx)
28+ defer cancel()
29+
30+ send := createPubCacheDrain(ctx, c.Log)
31+
32 surrogate := getSurrogateKey(c.User.Name, projectName)
33 return purgeCache(c.Cfg, send, surrogate)
34 }
35@@ -537,8 +549,16 @@ func (c *Cmd) cacheAll() error {
36 )
37 c.output("clearing http cache for all sites")
38 if c.Write {
39- ctx := context.Background()
40- defer ctx.Done()
41+ var ctx context.Context
42+ if s, ok := c.Session.(*pssh.SSHServerConnSession); ok {
43+ ctx = s.Context()
44+ } else {
45+ ctx = context.Background()
46+ }
47+
48+ ctx, cancel := context.WithCancel(ctx)
49+ defer cancel()
50+
51 send := createPubCacheDrain(ctx, c.Log)
52 return purgeAllCache(c.Cfg, send)
53 }