workspaceTTL returns the TTL to use for a workspace. If the template forbids custom workspace TTLs, then we always use the template's configured TTL (or 0 if the template has no TTL configured).
(workspace database.WorkspaceTable, templateSchedule TemplateScheduleOptions)
| 256 | // If the template forbids custom workspace TTLs, then we always use the |
| 257 | // template's configured TTL (or 0 if the template has no TTL configured). |
| 258 | func workspaceTTL(workspace database.WorkspaceTable, templateSchedule TemplateScheduleOptions) time.Duration { |
| 259 | // If the template forbids custom workspace TTLs, then we always use the |
| 260 | // template's configured TTL (or 0 if the template has no TTL configured). |
| 261 | if !templateSchedule.UserAutostopEnabled { |
| 262 | // This is intentionally a nested if statement because of the else if. |
| 263 | if templateSchedule.DefaultTTL > 0 { |
| 264 | return templateSchedule.DefaultTTL |
| 265 | } |
| 266 | return 0 |
| 267 | } |
| 268 | if workspace.Ttl.Valid { |
| 269 | return time.Duration(workspace.Ttl.Int64) |
| 270 | } |
| 271 | return 0 |
| 272 | } |
| 273 | |
| 274 | // truncateMidnight truncates a time to midnight in the time object's timezone. |
| 275 | // t.Truncate(24 * time.Hour) truncates based on the internal time and doesn't |
no test coverage detected