Skip to content

Commit

Permalink
Merge pull request #914 from treeverse/fix/export-check-previous-state
Browse files Browse the repository at this point in the history
fail export in case export is currently in progress
  • Loading branch information
nopcoder authored Nov 12, 2020
2 parents a0178c2 + d71c10f commit 78b6d8f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package export

import (
"context"
"errors"
"fmt"

nanoid "github.com/matoous/go-nanoid"
Expand All @@ -19,6 +20,8 @@ func getExportID(repo, branch, commitRef string) (string, error) {
return fmt.Sprintf("%s-%s-%s-%s", repo, branch, commitRef, nid), nil
}

var ErrExportInProgress = errors.New("export currently in progress")

// ExportBranchStart inserts a start task on branch, sets branch export state to pending.
// It returns an error if an export is already in progress.
func ExportBranchStart(paradeDB parade.Parade, cataloger catalog.Cataloger, repo, branch string) (string, error) {
Expand All @@ -32,6 +35,9 @@ func ExportBranchStart(paradeDB parade.Parade, cataloger catalog.Cataloger, repo
return "", err
}
err = cataloger.ExportState(repo, branch, commitRef, func(oldRef string, state catalog.CatalogBranchExportStatus) (newState catalog.CatalogBranchExportStatus, newMessage *string, err error) {
if state == catalog.ExportStatusInProgress {
return state, nil, ErrExportInProgress
}
config, err := cataloger.GetExportConfigurationForBranch(repo, branch)
if err != nil {
return "", nil, err
Expand Down

0 comments on commit 78b6d8f

Please sign in to comment.