@@ -10,7 +10,6 @@ import (
10
10
"net"
11
11
"net/http"
12
12
"strings"
13
- "time"
14
13
15
14
"github.com/google/uuid"
16
15
"github.com/hashicorp/yamux"
@@ -28,7 +27,6 @@ import (
28
27
"github.com/coder/coder/coderd/httpmw"
29
28
"github.com/coder/coder/coderd/provisionerdserver"
30
29
"github.com/coder/coder/coderd/rbac"
31
- "github.com/coder/coder/coderd/schedule"
32
30
"github.com/coder/coder/codersdk"
33
31
"github.com/coder/coder/provisionerd/proto"
34
32
)
@@ -310,85 +308,3 @@ func websocketNetConn(ctx context.Context, conn *websocket.Conn, msgType websock
310
308
}
311
309
}
312
310
313
- type EnterpriseTemplateScheduleStore struct {}
314
-
315
- var _ schedule.TemplateScheduleStore = & EnterpriseTemplateScheduleStore {}
316
-
317
- func (* EnterpriseTemplateScheduleStore ) GetTemplateScheduleOptions (ctx context.Context , db database.Store , templateID uuid.UUID ) (schedule.TemplateScheduleOptions , error ) {
318
- tpl , err := db .GetTemplateByID (ctx , templateID )
319
- if err != nil {
320
- return schedule.TemplateScheduleOptions {}, err
321
- }
322
-
323
- return schedule.TemplateScheduleOptions {
324
- UserAutostartEnabled : tpl .AllowUserAutostart ,
325
- UserAutostopEnabled : tpl .AllowUserAutostop ,
326
- DefaultTTL : time .Duration (tpl .DefaultTTL ),
327
- MaxTTL : time .Duration (tpl .MaxTTL ),
328
- FailureTTL : time .Duration (tpl .FailureTTL ),
329
- InactivityTTL : time .Duration (tpl .InactivityTTL ),
330
- LockedTTL : time .Duration (tpl .LockedTTL ),
331
- }, nil
332
- }
333
-
334
- func (* EnterpriseTemplateScheduleStore ) SetTemplateScheduleOptions (ctx context.Context , db database.Store , tpl database.Template , opts schedule.TemplateScheduleOptions ) (database.Template , error ) {
335
- if int64 (opts .DefaultTTL ) == tpl .DefaultTTL &&
336
- int64 (opts .MaxTTL ) == tpl .MaxTTL &&
337
- int64 (opts .FailureTTL ) == tpl .FailureTTL &&
338
- int64 (opts .InactivityTTL ) == tpl .InactivityTTL &&
339
- int64 (opts .LockedTTL ) == tpl .LockedTTL &&
340
- opts .UserAutostartEnabled == tpl .AllowUserAutostart &&
341
- opts .UserAutostopEnabled == tpl .AllowUserAutostop {
342
- // Avoid updating the UpdatedAt timestamp if nothing will be changed.
343
- return tpl , nil
344
- }
345
-
346
- template , err := db .UpdateTemplateScheduleByID (ctx , database.UpdateTemplateScheduleByIDParams {
347
- ID : tpl .ID ,
348
- UpdatedAt : database .Now (),
349
- AllowUserAutostart : opts .UserAutostartEnabled ,
350
- AllowUserAutostop : opts .UserAutostopEnabled ,
351
- DefaultTTL : int64 (opts .DefaultTTL ),
352
- MaxTTL : int64 (opts .MaxTTL ),
353
- FailureTTL : int64 (opts .FailureTTL ),
354
- InactivityTTL : int64 (opts .InactivityTTL ),
355
- LockedTTL : int64 (opts .LockedTTL ),
356
- })
357
- if err != nil {
358
- return database.Template {}, xerrors .Errorf ("update template schedule: %w" , err )
359
- }
360
-
361
- // Update all workspaces using the template to set the user defined schedule
362
- // to be within the new bounds. This essentially does the following for each
363
- // workspace using the template.
364
- // if (template.ttl != NULL) {
365
- // workspace.ttl = min(workspace.ttl, template.ttl)
366
- // }
367
- //
368
- // NOTE: this does not apply to currently running workspaces as their
369
- // schedule information is committed to the workspace_build during start.
370
- // This limitation is displayed to the user while editing the template.
371
- if opts .MaxTTL > 0 {
372
- err = db .UpdateWorkspaceTTLToBeWithinTemplateMax (ctx , database.UpdateWorkspaceTTLToBeWithinTemplateMaxParams {
373
- TemplateID : template .ID ,
374
- TemplateMaxTTL : int64 (opts .MaxTTL ),
375
- })
376
- if err != nil {
377
- return database.Template {}, xerrors .Errorf ("update TTL of all workspaces on template to be within new template max TTL: %w" , err )
378
- }
379
- }
380
-
381
- // If we updated the locked_ttl we need to update all the workspaces deleting_at
382
- // to ensure workspaces are being cleaned up correctly.
383
- if opts .LockedTTL > 0 {
384
- err = db .UpdateWorkspacesDeletingAtByTemplateID (ctx , database.UpdateWorkspacesDeletingAtByTemplateIDParams {
385
- TemplateID : template .ID ,
386
- LockedTtlMs : opts .LockedTTL .Milliseconds (),
387
- })
388
- if err != nil {
389
- return database.Template {}, xerrors .Errorf ("update deleting_at of all workspaces for new locked_ttl %q: %w" , opts .LockedTTL , err )
390
- }
391
- }
392
-
393
- return template , nil
394
- }
0 commit comments