(ctx context.Context, db database.Store, tpl database.Template, opts TemplateScheduleOptions)
| 201 | } |
| 202 | |
| 203 | func (*agplTemplateScheduleStore) Set(ctx context.Context, db database.Store, tpl database.Template, opts TemplateScheduleOptions) (database.Template, error) { |
| 204 | ctx, span := tracing.StartSpan(ctx) |
| 205 | defer span.End() |
| 206 | |
| 207 | if int64(opts.DefaultTTL) == tpl.DefaultTTL && int64(opts.ActivityBump) == tpl.ActivityBump { |
| 208 | // Avoid updating the UpdatedAt timestamp if nothing will be changed. |
| 209 | return tpl, nil |
| 210 | } |
| 211 | |
| 212 | var template database.Template |
| 213 | err := db.InTx(func(db database.Store) error { |
| 214 | err := db.UpdateTemplateScheduleByID(ctx, database.UpdateTemplateScheduleByIDParams{ |
| 215 | ID: tpl.ID, |
| 216 | UpdatedAt: dbtime.Now(), |
| 217 | DefaultTTL: int64(opts.DefaultTTL), |
| 218 | ActivityBump: int64(opts.ActivityBump), |
| 219 | // Don't allow changing these settings, but keep the value in the DB (to |
| 220 | // avoid clearing settings if the license has an issue). |
| 221 | AutostopRequirementDaysOfWeek: tpl.AutostopRequirementDaysOfWeek, |
| 222 | AutostopRequirementWeeks: tpl.AutostopRequirementWeeks, |
| 223 | AutostartBlockDaysOfWeek: tpl.AutostartBlockDaysOfWeek, |
| 224 | AllowUserAutostart: tpl.AllowUserAutostart, |
| 225 | AllowUserAutostop: tpl.AllowUserAutostop, |
| 226 | FailureTTL: tpl.FailureTTL, |
| 227 | TimeTilDormant: tpl.TimeTilDormant, |
| 228 | TimeTilDormantAutoDelete: tpl.TimeTilDormantAutoDelete, |
| 229 | }) |
| 230 | if err != nil { |
| 231 | return xerrors.Errorf("update template schedule: %w", err) |
| 232 | } |
| 233 | |
| 234 | template, err = db.GetTemplateByID(ctx, tpl.ID) |
| 235 | if err != nil { |
| 236 | return xerrors.Errorf("fetch updated template: %w", err) |
| 237 | } |
| 238 | |
| 239 | return nil |
| 240 | }, nil) |
| 241 | if err != nil { |
| 242 | return database.Template{}, err |
| 243 | } |
| 244 | |
| 245 | return template, err |
| 246 | } |
nothing calls this directly
no test coverage detected