mirror of
https://github.com/harness/drone.git
synced 2025-05-19 18:39:56 +08:00
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
// Copyright 2022 Harness Inc. All rights reserved.
|
|
// Use of this source code is governed by the Polyform Free Trial License
|
|
// that can be found in the LICENSE.md file for this repository.
|
|
|
|
package logs
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
)
|
|
|
|
// NewCombined returns a new combined log store that will fallback
|
|
// to a secondary log store when necessary. This can be useful when
|
|
// migrating from database logs to s3, where logs for older builds
|
|
// are still being stored in the database, and newer logs in s3.
|
|
func NewCombined(primary, secondary LogStore) LogStore {
|
|
return &combined{
|
|
primary: primary,
|
|
secondary: secondary,
|
|
}
|
|
}
|
|
|
|
type combined struct {
|
|
primary, secondary LogStore
|
|
}
|
|
|
|
func (s *combined) Find(ctx context.Context, step int64) (io.ReadCloser, error) {
|
|
rc, err := s.primary.Find(ctx, step)
|
|
if err == nil {
|
|
return rc, nil
|
|
}
|
|
return s.secondary.Find(ctx, step)
|
|
}
|
|
|
|
func (s *combined) Create(ctx context.Context, step int64, r io.Reader) error {
|
|
return s.primary.Create(ctx, step, r)
|
|
}
|
|
|
|
func (s *combined) Update(ctx context.Context, step int64, r io.Reader) error {
|
|
return s.primary.Update(ctx, step, r)
|
|
}
|
|
|
|
func (s *combined) Delete(ctx context.Context, step int64) error {
|
|
err := s.primary.Delete(ctx, step)
|
|
if err != nil {
|
|
err = s.secondary.Delete(ctx, step)
|
|
}
|
|
return err
|
|
}
|