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

建议:临时任务可否支持持久化 #31

Open
3zengzz opened this issue Dec 27, 2023 · 2 comments
Open

建议:临时任务可否支持持久化 #31

3zengzz opened this issue Dec 27, 2023 · 2 comments

Comments

@3zengzz
Copy link

3zengzz commented Dec 27, 2023

建议:临时任务可否支持持久化,类似发短信,消息之类的任务,像hangfire 支持持久化,在可视面板查看错误信息重试。

@2881099
Copy link
Owner

2881099 commented Dec 27, 2023

可以使用 AddTask 解决

static ConcurrentDictionary<string, Action> _tempTasks = new ConcurrentDictionary<string, Action>();

void OnExecuting(TaskInfo task)
{
    if (task.Topic == "tempTask")
    {
        if (_tempTasks.TryGetValue(task.Id, out var handler))
        {
            handler?.Invoke();
            _tempTasks.TryRemove(task.Id, _);
        }
    }
}

var taskId = scheduler.AddTask(topic: "tempTask", round: 1, body: "", seconds: 10);
_tempTasks.TryAdd(taskId, () => {
    Console.WriteLine("...");
});

@3zengzz
Copy link
Author

3zengzz commented Dec 27, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants