2022-09-05 13:29:11 +08:00
|
|
|
package rootcoord
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
2022-09-24 12:42:51 +08:00
|
|
|
type task interface {
|
2022-09-05 13:29:11 +08:00
|
|
|
GetCtx() context.Context
|
|
|
|
SetCtx(context.Context)
|
|
|
|
SetTs(ts Timestamp)
|
|
|
|
GetTs() Timestamp
|
|
|
|
SetID(id UniqueID)
|
|
|
|
GetID() UniqueID
|
|
|
|
Prepare(ctx context.Context) error
|
|
|
|
Execute(ctx context.Context) error
|
|
|
|
WaitToFinish() error
|
|
|
|
NotifyDone(err error)
|
|
|
|
}
|
|
|
|
|
2022-09-24 12:42:51 +08:00
|
|
|
type baseTask struct {
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx context.Context
|
|
|
|
core *Core
|
|
|
|
done chan error
|
|
|
|
ts Timestamp
|
|
|
|
id UniqueID
|
|
|
|
}
|
|
|
|
|
2022-09-24 12:42:51 +08:00
|
|
|
func (b *baseTask) SetCtx(ctx context.Context) {
|
2022-09-05 13:29:11 +08:00
|
|
|
b.ctx = ctx
|
|
|
|
}
|
|
|
|
|
2022-09-24 12:42:51 +08:00
|
|
|
func (b *baseTask) GetCtx() context.Context {
|
2022-09-05 13:29:11 +08:00
|
|
|
return b.ctx
|
|
|
|
}
|
|
|
|
|
2022-09-24 12:42:51 +08:00
|
|
|
func (b *baseTask) SetTs(ts Timestamp) {
|
2022-09-05 13:29:11 +08:00
|
|
|
b.ts = ts
|
|
|
|
}
|
|
|
|
|
2022-09-24 12:42:51 +08:00
|
|
|
func (b *baseTask) GetTs() Timestamp {
|
2022-09-05 13:29:11 +08:00
|
|
|
return b.ts
|
|
|
|
}
|
|
|
|
|
2022-09-24 12:42:51 +08:00
|
|
|
func (b *baseTask) SetID(id UniqueID) {
|
2022-09-05 13:29:11 +08:00
|
|
|
b.id = id
|
|
|
|
}
|
|
|
|
|
2022-09-24 12:42:51 +08:00
|
|
|
func (b *baseTask) GetID() UniqueID {
|
2022-09-05 13:29:11 +08:00
|
|
|
return b.id
|
|
|
|
}
|
|
|
|
|
2022-09-24 12:42:51 +08:00
|
|
|
func (b *baseTask) Prepare(ctx context.Context) error {
|
2022-09-05 13:29:11 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-24 12:42:51 +08:00
|
|
|
func (b *baseTask) Execute(ctx context.Context) error {
|
2022-09-05 13:29:11 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-24 12:42:51 +08:00
|
|
|
func (b *baseTask) WaitToFinish() error {
|
2022-09-05 13:29:11 +08:00
|
|
|
return <-b.done
|
|
|
|
}
|
|
|
|
|
2022-09-24 12:42:51 +08:00
|
|
|
func (b *baseTask) NotifyDone(err error) {
|
2022-09-05 13:29:11 +08:00
|
|
|
b.done <- err
|
|
|
|
}
|