Skip to content

Commit

Permalink
Only set LastRunTime if periodic output was successful (#72)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Kim <[email protected]>
  • Loading branch information
Oats87 authored Feb 15, 2022
1 parent ad236ef commit 278280e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/applyinator/applyinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,14 @@ func (a *Applyinator) Apply(ctx context.Context, input ApplyInput) (ApplyOutput,

periodicApplySucceeded := true
for index, instruction := range input.CalculatedPlan.Plan.PeriodicInstructions {
var previousRunTime string
if po, ok := periodicOutputs[instruction.Name]; ok {
logrus.Debugf("[Applyinator] Got periodic output and am now parsing last run time %s", po.LastRunTime)
t, err := time.Parse(time.UnixDate, po.LastRunTime)
if err != nil {
logrus.Errorf("error encountered during parsing of last run time: %v", err)
} else {
previousRunTime = po.LastRunTime
if instruction.PeriodSeconds == 0 {
instruction.PeriodSeconds = 600 // set default period to 600 seconds
}
Expand All @@ -277,12 +279,16 @@ func (a *Applyinator) Apply(ctx context.Context, input ApplyInput) (ApplyOutput,
if instruction.Name == "" {
logrus.Errorf("instruction does not have a name set, cannot save output data")
} else {
lrt := nowUnixTimeString
if exitCode != 0 {
lrt = previousRunTime
}
periodicOutputs[instruction.Name] = PeriodicInstructionOutput{
Name: instruction.Name,
Stdout: stdout,
Stderr: stderr,
ExitCode: exitCode,
LastRunTime: nowUnixTimeString,
LastRunTime: lrt,
}
}
if !periodicApplySucceeded {
Expand Down

0 comments on commit 278280e

Please sign in to comment.