mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(coderd): make activitybump aware of default template ttl (#10253)
The refactored ActivityBump query did not take into account the template-level TTL, resulting in potentially incorrect bump amounts for workspaces that have both a user-defined and template- defined TTL that differ. This change is ported over from PR#10035 to reduce the overall size of that PR. Also includes a drive-by unit test in autobuild for checking template autostop/TTL. Co-authored-by: Dean Sheather <dean@deansheather.com>
This commit is contained in:
co-authored by
Dean Sheather
parent
2a4ac2a53c
commit
d56f49f619
@@ -814,8 +814,26 @@ func (q *FakeQuerier) ActivityBumpWorkspace(ctx context.Context, workspaceID uui
|
||||
if q.workspaceBuilds[i].Deadline.IsZero() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Check the template default TTL.
|
||||
template, err := q.getTemplateByIDNoLock(ctx, workspace.TemplateID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var ttlDur time.Duration
|
||||
if workspace.Ttl.Valid {
|
||||
ttlDur = time.Duration(workspace.Ttl.Int64)
|
||||
}
|
||||
if !template.AllowUserAutostop {
|
||||
ttlDur = time.Duration(template.DefaultTTL)
|
||||
}
|
||||
if ttlDur <= 0 {
|
||||
// There's no TTL set anymore, so we don't know the bump duration.
|
||||
return nil
|
||||
}
|
||||
|
||||
// Only bump if 5% of the deadline has passed.
|
||||
ttlDur := time.Duration(workspace.Ttl.Int64)
|
||||
ttlDur95 := ttlDur - (ttlDur / 20)
|
||||
minBumpDeadline := q.workspaceBuilds[i].Deadline.Add(-ttlDur95)
|
||||
if now.Before(minBumpDeadline) {
|
||||
|
||||
Reference in New Issue
Block a user