@@ -2,8 +2,6 @@ package coderd
2
2
3
3
import (
4
4
"context"
5
- "database/sql"
6
- "errors"
7
5
"time"
8
6
9
7
"github.com/google/uuid"
@@ -23,67 +21,73 @@ func activityBumpWorkspace(ctx context.Context, log slog.Logger, db database.Sto
23
21
defer cancel ()
24
22
25
23
err := db .InTx (func (s database.Store ) error {
26
- build , err := s .GetLatestWorkspaceBuildByWorkspaceID (ctx , workspaceID )
27
- if errors . Is ( err , sql . ErrNoRows ) {
28
- return nil
29
- } else if err != nil {
30
- return xerrors .Errorf ("get latest workspace build : %w" , err )
24
+ if err := s .ActivityBumpWorkspace (ctx , database. ActivityBumpWorkspaceParams {
25
+ WorkspaceID : workspaceID ,
26
+ UpdatedAt : dbtime . Now (),
27
+ }); err != nil {
28
+ return xerrors .Errorf ("activity bump workspace: %w" , err )
31
29
}
30
+ // build, err := s.GetLatestWorkspaceBuildByWorkspaceID(ctx, workspaceID)
31
+ // if errors.Is(err, sql.ErrNoRows) {
32
+ // return nil
33
+ // } else if err != nil {
34
+ // return xerrors.Errorf("get latest workspace build: %w", err)
35
+ // }
32
36
33
- job , err := s .GetProvisionerJobByID (ctx , build .JobID )
34
- if err != nil {
35
- return xerrors .Errorf ("get provisioner job: %w" , err )
36
- }
37
+ // job, err := s.GetProvisionerJobByID(ctx, build.JobID)
38
+ // if err != nil {
39
+ // return xerrors.Errorf("get provisioner job: %w", err)
40
+ // }
37
41
38
- if build .Transition != database .WorkspaceTransitionStart || ! job .CompletedAt .Valid {
39
- return nil
40
- }
42
+ // if build.Transition != database.WorkspaceTransitionStart || !job.CompletedAt.Valid {
43
+ // return nil
44
+ // }
41
45
42
- if build .Deadline .IsZero () {
43
- // Workspace shutdown is manual
44
- return nil
45
- }
46
+ // if build.Deadline.IsZero() {
47
+ // // Workspace shutdown is manual
48
+ // return nil
49
+ // }
46
50
47
- workspace , err := s .GetWorkspaceByID (ctx , workspaceID )
48
- if err != nil {
49
- return xerrors .Errorf ("get workspace: %w" , err )
50
- }
51
-
52
- var (
53
- // We bump by the original TTL to prevent counter-intuitive behavior
54
- // as the TTL wraps. For example, if I set the TTL to 12 hours, sign off
55
- // work at midnight, come back at 10am, I would want another full day
56
- // of uptime. In the prior implementation, the workspace would enter
57
- // a state of always expiring 1 hour in the future
58
- bumpAmount = time .Duration (workspace .Ttl .Int64 )
59
- // DB writes are expensive so we only bump when 5% of the deadline
60
- // has elapsed.
61
- bumpEvery = bumpAmount / 20
62
- timeSinceLastBump = bumpAmount - time .Until (build .Deadline )
63
- )
51
+ // workspace, err := s.GetWorkspaceByID(ctx, workspaceID)
52
+ // if err != nil {
53
+ // return xerrors.Errorf("get workspace: %w", err)
54
+ // }
64
55
65
- if timeSinceLastBump < bumpEvery {
66
- return nil
67
- }
56
+ // var (
57
+ // We bump by the original TTL to prevent counter-intuitive behavior
58
+ // as the TTL wraps. For example, if I set the TTL to 12 hours, sign off
59
+ // work at midnight, come back at 10am, I would want another full day
60
+ // of uptime. In the prior implementation, the workspace would enter
61
+ // a state of always expiring 1 hour in the future
62
+ // bumpAmount = time.Duration(workspace.Ttl.Int64)
63
+ // DB writes are expensive so we only bump when 5% of the deadline
64
+ // has elapsed.
65
+ // bumpEvery = bumpAmount / 20
66
+ // timeSinceLastBump = bumpAmount - time.Until(build.Deadline)
67
+ // )
68
68
69
- if bumpAmount == 0 {
70
- return nil
71
- }
72
-
73
- newDeadline := dbtime .Now ().Add (bumpAmount )
74
- if ! build .MaxDeadline .IsZero () && newDeadline .After (build .MaxDeadline ) {
75
- newDeadline = build .MaxDeadline
76
- }
77
-
78
- if err := s .UpdateWorkspaceBuildByID (ctx , database.UpdateWorkspaceBuildByIDParams {
79
- ID : build .ID ,
80
- UpdatedAt : dbtime .Now (),
81
- ProvisionerState : build .ProvisionerState ,
82
- Deadline : newDeadline ,
83
- MaxDeadline : build .MaxDeadline ,
84
- }); err != nil {
85
- return xerrors .Errorf ("update workspace build: %w" , err )
86
- }
69
+ // if timeSinceLastBump < bumpEvery {
70
+ // return nil
71
+ // }
72
+ //
73
+ // if bumpAmount == 0 {
74
+ // return nil
75
+ // }
76
+ //
77
+ // newDeadline := dbtime.Now().Add(bumpAmount)
78
+ // if !build.MaxDeadline.IsZero() && newDeadline.After(build.MaxDeadline) {
79
+ // newDeadline = build.MaxDeadline
80
+ // }
81
+ //
82
+ // if err := s.UpdateWorkspaceBuildByID(ctx, database.UpdateWorkspaceBuildByIDParams{
83
+ // ID: build.ID,
84
+ // UpdatedAt: dbtime.Now(),
85
+ // ProvisionerState: build.ProvisionerState,
86
+ // Deadline: newDeadline,
87
+ // MaxDeadline: build.MaxDeadline,
88
+ // }); err != nil {
89
+ // return xerrors.Errorf("update workspace build: %w", err)
90
+ // }
87
91
return nil
88
92
}, nil )
89
93
if err != nil {
0 commit comments