2023-03-22 15:37:26 +00:00
|
|
|
package lock
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/libs/log"
|
2023-03-22 15:37:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type release struct{}
|
|
|
|
|
|
|
|
func Release() bundle.Mutator {
|
|
|
|
return &release{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *release) Name() string {
|
|
|
|
return "lock:release"
|
|
|
|
}
|
|
|
|
|
2023-05-24 12:45:19 +00:00
|
|
|
func (m *release) Apply(ctx context.Context, b *bundle.Bundle) error {
|
2023-03-22 15:37:26 +00:00
|
|
|
// Return early if locking is disabled.
|
|
|
|
if !b.Config.Bundle.Lock.IsEnabled() {
|
|
|
|
log.Infof(ctx, "Skipping; locking is disabled")
|
2023-05-24 12:45:19 +00:00
|
|
|
return nil
|
2023-03-22 15:37:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return early if the locker is not set.
|
|
|
|
// It is likely an error occurred prior to initialization of the locker instance.
|
|
|
|
if b.Locker == nil {
|
|
|
|
log.Warnf(ctx, "Unable to release lock if locker is not configured")
|
2023-05-24 12:45:19 +00:00
|
|
|
return nil
|
2023-03-22 15:37:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Infof(ctx, "Releasing deployment lock")
|
|
|
|
err := b.Locker.Unlock(ctx)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf(ctx, "Failed to release deployment lock: %v", err)
|
2023-05-24 12:45:19 +00:00
|
|
|
return err
|
2023-03-22 15:37:26 +00:00
|
|
|
}
|
|
|
|
|
2023-05-24 12:45:19 +00:00
|
|
|
return nil
|
2023-03-22 15:37:26 +00:00
|
|
|
}
|