mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 08:20:25 +08:00 
			
		
		
		
	!85 fix: 修复 BINLOG同步任务加载问题
* Merge branch 'dev' of gitee.com:dromara/mayfly-go into feat-db-bak * fix: 修复 BINLOG 同步任务加载问题
This commit is contained in:
		@@ -11,9 +11,11 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	ErrNotFound = errors.New("job not found")
 | 
			
		||||
	ErrExist    = errors.New("job already exists")
 | 
			
		||||
	ErrFinished = errors.New("job already finished")
 | 
			
		||||
	ErrJobNotFound = errors.New("job not found")
 | 
			
		||||
	ErrJobExist    = errors.New("job already exists")
 | 
			
		||||
	ErrJobFinished = errors.New("job already finished")
 | 
			
		||||
	ErrJobDisabled = errors.New("job has been disabled")
 | 
			
		||||
	ErrJobTimeout  = errors.New("job has timed out")
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type JobKey = string
 | 
			
		||||
@@ -236,7 +238,7 @@ func (r *Runner[T]) afterRun(wrap *wrapper[T]) {
 | 
			
		||||
func (r *Runner[T]) doScheduleJob(job T, finished bool) (time.Time, error) {
 | 
			
		||||
	if r.scheduleJob == nil {
 | 
			
		||||
		if finished {
 | 
			
		||||
			return time.Time{}, ErrFinished
 | 
			
		||||
			return time.Time{}, ErrJobFinished
 | 
			
		||||
		}
 | 
			
		||||
		return time.Now(), nil
 | 
			
		||||
	}
 | 
			
		||||
@@ -293,7 +295,7 @@ func (r *Runner[T]) Add(ctx context.Context, job T) error {
 | 
			
		||||
	defer r.mutex.Unlock()
 | 
			
		||||
 | 
			
		||||
	if _, ok := r.all[job.GetKey()]; ok {
 | 
			
		||||
		return ErrExist
 | 
			
		||||
		return ErrJobExist
 | 
			
		||||
	}
 | 
			
		||||
	deadline, err := r.doScheduleJob(job, false)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -358,7 +360,7 @@ func (r *Runner[T]) Remove(ctx context.Context, key JobKey) error {
 | 
			
		||||
 | 
			
		||||
	wrap, ok := r.all[key]
 | 
			
		||||
	if !ok {
 | 
			
		||||
		return ErrNotFound
 | 
			
		||||
		return ErrJobNotFound
 | 
			
		||||
	}
 | 
			
		||||
	switch wrap.status {
 | 
			
		||||
	case JobDelaying:
 | 
			
		||||
 
 | 
			
		||||
@@ -75,7 +75,7 @@ func TestRunner_AddJob(t *testing.T) {
 | 
			
		||||
		{
 | 
			
		||||
			name: "repetitive job",
 | 
			
		||||
			job:  newTestJob("dual"),
 | 
			
		||||
			want: ErrExist,
 | 
			
		||||
			want: ErrJobExist,
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	runner := NewRunner[*testJob](1, func(ctx context.Context, job *testJob) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user