MCPcopy Index your code
hub / github.com/PatchMon/PatchMon / CreateRun

Method CreateRun

server-source-code/internal/store/patching.go:249–295  ·  view source on GitHub ↗

CreateRun creates a new patch run. If id is empty, a new UUID is generated. triggeredByUserID is the user who initiated the run (optional; nil for agent/system). dryRun when true creates a validation-only run with status "pending_validation". scheduledAt is when the patch will run (optional; nil for

(ctx context.Context, id, hostID, jobID, patchType string, packageName *string, packageNames []string, triggeredByUserID *string, dryRun bool, scheduledAt *time.Time, policyID, policyName *string, policySnapshot []byte, opts *CreateRunOpts)

Source from the content-addressed store, hash-verified

247// policyID, policyName, policySnapshot capture the effective policy at trigger time (all optional).
248// opts.InitialStatus, if non-empty, overrides the dry-run-derived status.
249func (s *PatchRunsStore) CreateRun(ctx context.Context, id, hostID, jobID, patchType string, packageName *string, packageNames []string, triggeredByUserID *string, dryRun bool, scheduledAt *time.Time, policyID, policyName *string, policySnapshot []byte, opts *CreateRunOpts) (string, error) {
250 if id == "" {
251 id = uuid.New().String()
252 }
253 var pkgNames []byte
254 if len(packageNames) > 0 {
255 var err error
256 pkgNames, err = json.Marshal(packageNames)
257 if err != nil {
258 return "", err
259 }
260 }
261 status := "queued"
262 if dryRun {
263 status = "pending_validation"
264 }
265 if opts != nil && opts.InitialStatus != "" {
266 status = opts.InitialStatus
267 }
268 sched := pgtime.FromPtr(scheduledAt)
269 var validationRunID *string
270 var approvedByUserID *string
271 if opts != nil {
272 validationRunID = opts.ValidationRunID
273 approvedByUserID = opts.ApprovedByUserID
274 }
275 d := s.db.DB(ctx)
276 err := d.Queries.CreatePatchRun(ctx, db.CreatePatchRunParams{
277 ID: id,
278 HostID: hostID,
279 JobID: jobID,
280 PatchType: patchType,
281 PackageName: packageName,
282 PackageNames: pkgNames,
283 Status: status,
284 ShellOutput: "",
285 TriggeredByUserID: triggeredByUserID,
286 DryRun: dryRun,
287 ScheduledAt: sched,
288 PolicyID: policyID,
289 PolicyName: policyName,
290 PolicySnapshot: policySnapshot,
291 ValidationRunID: validationRunID,
292 ApprovedByUserID: approvedByUserID,
293 })
294 return id, err
295}
296
297// GetByID returns a patch run by ID with host info.
298func (s *PatchRunsStore) GetByID(ctx context.Context, id string) (*db.GetPatchRunByIDRow, error) {

Callers 2

ApproveRunMethod · 0.80
TriggerMethod · 0.80

Calls 2

DBMethod · 0.65
CreatePatchRunMethod · 0.65

Tested by

no test coverage detected