| 101 | } |
| 102 | |
| 103 | func ExecuteCleanMethod(ctx context.Context, module CleanExecutionMethod, execIO *ExecutionIO) (err error) { |
| 104 | log := zerolog.Ctx(ctx) |
| 105 | |
| 106 | if err = ExecuteMethod(ctx, module, execIO); err != nil { |
| 107 | return |
| 108 | } |
| 109 | |
| 110 | if err = module.Clean(ctx); err != nil { |
| 111 | log.Error().Err(err).Msg("Module cleanup failed") |
| 112 | err = nil |
| 113 | } |
| 114 | |
| 115 | if execIO.Output != nil && execIO.Output.Provider != nil { |
| 116 | log.Info().Msg("Collecting output") |
| 117 | |
| 118 | defer func() { |
| 119 | if cleanErr := execIO.Clean(ctx); cleanErr != nil { |
| 120 | log.Debug().Err(cleanErr).Msg("Output provider cleanup failed") |
| 121 | } |
| 122 | }() |
| 123 | |
| 124 | if err := execIO.GetOutput(ctx); err != nil { |
| 125 | log.Error().Err(err).Msg("Output collection failed") |
| 126 | return fmt.Errorf("get output: %w", err) |
| 127 | } |
| 128 | log.Debug().Msg("Output collection succeeded") |
| 129 | } |
| 130 | return |
| 131 | } |