Skip to content

Commit

Permalink
Clean up activity take several paths as input
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielCosme committed Aug 12, 2024
1 parent 8ce7e5b commit 1c3f844
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
12 changes: 7 additions & 5 deletions internal/workflow/activities/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ func NewCleanUpActivity() *CleanUpActivity {
}

type CleanUpActivityParams struct {
FullPath string
Paths []string
}

func (a *CleanUpActivity) Execute(ctx context.Context, params *CleanUpActivityParams) error {
if params == nil || params.FullPath == "" {
return fmt.Errorf("error processing parameters: missing or empty")
if params == nil {
return fmt.Errorf("error processing parameters: missing")

Check warning on line 22 in internal/workflow/activities/cleanup.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/cleanup.go#L21-L22

Added lines #L21 - L22 were not covered by tests
}

if err := os.RemoveAll(params.FullPath); err != nil {
return fmt.Errorf("error removing transfer directory: %v", err)
for _, p := range params.Paths {
if err := os.RemoveAll(p); err != nil {
return fmt.Errorf("error removing path: %v", err)

Check warning on line 27 in internal/workflow/activities/cleanup.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/cleanup.go#L25-L27

Added lines #L25 - L27 were not covered by tests
}
}

return nil
Expand Down
32 changes: 12 additions & 20 deletions internal/workflow/processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,31 +529,23 @@ func (w *ProcessingWorkflow) SessionHandler(sessCtx temporalsdk_workflow.Context
defer func() {
// We need disconnected context here because when session gets released the cleanup
// activities get scheduled and then immediately canceled.
cleanUpContext, cancel := temporalsdk_workflow.NewDisconnectedContext(sessCtx)
defer cancel()
var filesToRemove []string

Check warning on line 532 in internal/workflow/processing.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/processing.go#L532

Added line #L532 was not covered by tests
if tinfo.Bundle.FullPathBeforeStrip != "" {
activityOpts := withActivityOptsForLocalAction(cleanUpContext)
if err := temporalsdk_workflow.ExecuteActivity(activityOpts, activities.CleanUpActivityName, &activities.CleanUpActivityParams{
FullPath: tinfo.Bundle.FullPathBeforeStrip,
}).Get(activityOpts, nil); err != nil {
w.logger.Error(err, "failed to clean up", "path", tinfo.Bundle.FullPathBeforeStrip)
}
filesToRemove = append(filesToRemove, tinfo.Bundle.FullPathBeforeStrip)

Check warning on line 534 in internal/workflow/processing.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/processing.go#L534

Added line #L534 was not covered by tests
}
if tempBlob != "" {
activityOpts := withActivityOptsForLocalAction(cleanUpContext)
if err := temporalsdk_workflow.ExecuteActivity(activityOpts, activities.CleanUpActivityName, &activities.CleanUpActivityParams{
FullPath: tempBlob,
}).Get(activityOpts, nil); err != nil {
w.logger.Error(err, "failed to clean up", "path", tempBlob)
}
filesToRemove = append(filesToRemove, tempBlob)

Check warning on line 537 in internal/workflow/processing.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/processing.go#L536-L537

Added lines #L536 - L537 were not covered by tests
}
if tempExtracted != "" {
activityOpts := withActivityOptsForLocalAction(cleanUpContext)
if err := temporalsdk_workflow.ExecuteActivity(activityOpts, activities.CleanUpActivityName, &activities.CleanUpActivityParams{
FullPath: tempExtracted,
}).Get(activityOpts, nil); err != nil {
w.logger.Error(err, "failed to clean up", "path", tempExtracted)
}
filesToRemove = append(filesToRemove, tempExtracted)

Check warning on line 540 in internal/workflow/processing.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/processing.go#L539-L540

Added lines #L539 - L540 were not covered by tests
}
cleanUpCtx, cancel := temporalsdk_workflow.NewDisconnectedContext(sessCtx)
defer cancel()
activityOpts := withActivityOptsForLocalAction(cleanUpCtx)
if err := temporalsdk_workflow.ExecuteActivity(activityOpts, activities.CleanUpActivityName, &activities.CleanUpActivityParams{
Paths: filesToRemove,
}).Get(activityOpts, nil); err != nil {
w.logger.Error(err, "failed to clean up temporary files", "path", tempExtracted)

Check warning on line 548 in internal/workflow/processing.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/processing.go#L542-L548

Added lines #L542 - L548 were not covered by tests
}
}()

Expand Down

0 comments on commit 1c3f844

Please sign in to comment.