/
sleep.go
52 lines (43 loc) · 1.15 KB
/
sleep.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* File: sleep.go
* Author: Ming Cheng<mingcheng@outlook.com>
*
* Created Date: Saturday, July 6th 2019, 11:19:12 pm
* Last Modified: Friday, July 22nd 2022, 2:00:15 pm
*
* http://www.opensource.org/licenses/MIT
*/
package buckets
import (
"context"
"math/rand"
"time"
log "github.com/sirupsen/logrus"
"github.com/mingcheng/obsync"
)
// TestBucket is a test buckets
type TestBucket struct {
Config *obsync.BucketConfig
}
// Info to get the buckets info
func (r *TestBucket) Info(ctx context.Context) (interface{}, error) {
return "This is a test buckets", nil
}
// Exists to check if the file exists
func (r *TestBucket) Exists(ctx context.Context, path string) bool {
return false
}
// Put to put the file to the buckets
func (r *TestBucket) Put(ctx context.Context, path, key string) error {
log.Debugf("received path [%s] and key [%s]", path, key)
time.Sleep(time.Duration(rand.Intn(5)) * time.Second)
return nil
}
// init function to initialize and register the buckets
func init() {
_ = obsync.AddBucketSyncFunc("sleep", func(config obsync.BucketConfig) (obsync.BucketSync, error) {
return &TestBucket{
Config: &config,
}, nil
})
}