RichardKnop / machinery

Machinery is an asynchronous task queue/job queue based on distributed message passing.
Mozilla Public License 2.0
7.55k stars 917 forks source link

Question : Cancel Periodic tasks? #812

Open rnbokade opened 3 months ago

rnbokade commented 3 months ago

I am building a sensor management system, where in I want to be able to add periodic tasks for polling sensors at specific intervals. however, the web interface would also allow, the user to tweak the polling interval of particular sensor as such. So I want to be able to remove the scheduled job and schedule a new one. How to do this?

xiaoz194 commented 1 month ago

hello, I also have some problem about regist periodic tasks,could u please help me?

my code like this, my normal task is ok, but periodic task is failure, error msg is : "checkAllJobs" Task not registered with this worker.

I don't know which step is wrong.

{
        // .....

    // regist tasks
    tasksMap := initAsyncTaskMap()
    err = server.RegisterTasks(tasksMap) // ok
    // regist periodic task 
    signature := &tasks.Signature{
        Name: "checkAllJobs",
    }
    if !server.IsTaskRegistered("checkAllJobs") {
        logutil.G(ctx).Infof("checkAllJobs task not regist")
        err = server.RegisterPeriodicTask("1 * * * ?", "checkAllJobs", signature)       // failed err: task not register
    }
    return server, err
}

func initAsyncTaskMap() map[string]interface{} {
    tasksMap := map[string]interface{}{
        "produce":      task.Produce,                      // this is normal task, and everything is ok
        "checkAllJobs": task.CheckAllJobs,      // this is periodic tasks
    }
    return tasksMap
}