Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新 timed_task.go 增加了两个方法 #1504

Merged
merged 1 commit into from
Aug 9, 2023

Commits on Aug 8, 2023

  1. 更新 timed_task.go 增加了两个方法

    Add:Timer工具增加AddTaskByFuncWithSeconds与AddTaskByJobWithSeconds方法
    Fix:解决添加定时任务没有按时运行问题
    // AddTaskByFuncWithSeconds 通过函数的方法使用WithSeconds添加任务
    func (t *timer) AddTaskByFuncWhithSecond(taskName string, spec string, task func(), option ...cron.Option) (cron.EntryID, error) {
    	t.Lock()
    	defer t.Unlock()
    	option = append(option, cron.WithSeconds())
    	if _, ok := t.taskList[taskName]; !ok {
    		t.taskList[taskName] = cron.New(option...)
    	}
    	id, err := t.taskList[taskName].AddFunc(spec, task)
    	t.taskList[taskName].Start()
    	return id, err
    }
    
    
    // AddTaskByJobWithSeconds 通过接口的方法添加任务
    func (t *timer) AddTaskByJobWithSeconds(taskName string, spec string, job interface{ Run() }, option ...cron.Option) (cron.EntryID, error) {
    	t.Lock()
    	defer t.Unlock()
    	option = append(option, cron.WithSeconds())
    	if _, ok := t.taskList[taskName]; !ok {
    		t.taskList[taskName] = cron.New(option...)
    	}
    	id, err := t.taskList[taskName].AddJob(spec, job)
    	t.taskList[taskName].Start()
    	return id, err
    }
    yaoyaochil committed Aug 8, 2023
    Configuration menu
    Copy the full SHA
    8fb02ab View commit details
    Browse the repository at this point in the history