Quartz.Net 工作进展

发布于 2024-07-30 15:23:22 字数 121 浏览 5 评论 0原文

IJob 是否有一种简单的方法可以从作业中发布数据。 我有一个正在运行导入过程的作业,但希望通过查找该作业并请求它来检索进度。

我认为我也许可以使用 JobDetails,但似乎没有反映作业中所做的更改?

Is there an easy way for a IJob to publish data from within the Job. I have a Job running an import process, but would like to retrieve the progress by looking up the Job and requesting it.

I thought that i may be able to use the JobDetails, but does not seem to reflect the changes made within the Job?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海里的那抹蓝 2024-08-06 15:23:57

没有一种内置方法可以轻松地为您提供您正在寻找的东西。 但通过发布订阅向其他设施发布进度信息也不是那么困难。 您还可以定期将进度信息写入持久存储 - 当您知道处理的最后一个成功位时,这也将为您带来轻松重试的好处。

如果外部线程/进程轮询您要导入的目标,并且您将在某处获得有关要导入的总项目的信息,则它也可以确定状态。

Quartz.NET 作业是作为一个......井单元进行处理的单元,因此不存在还有多少工作要做的概念。 或者您在另一项依赖于导入流程的工作中需要此信息吗?

There isn't a built-in way that would give you easily the thing you are looking for. But it isn't that hard to publish progress info to some other facility via publish subscribe either. You could also periodically write progress info to persistent storage - that would also give you the benefit of easy retry when you know the last successful bit that was processed.

An outside thread/process could also determine the status if it polled the target where you are importing and you would have somewhere the info about total items that are going to be imported.

Quartz.NET jobs are units that are processed as an.. well unit and so there isn't the notion of how much there is yet to be done. Or do you need this info in another job that depends on import process?

平生欢 2024-08-06 15:23:48

这是很有可能。

我会选择这样的东西。
在作业中:

public virtual void Execute(IJobExecutionContext context)
{
    int i = 0;
    while (i++ < 100)
    {
        context.JobDetail.JobDataMap["progress"] = i;
        Thread.Sleep(1000);
    }
}

在想要检索进度的代码中:

var jobs = scheduler.GetCurrentlyExecutingJobs();
foreach (var j in jobs)
{
    Console.WriteLine("Progress of {0} is {1}", 
        j.JobDetail.Key, 
        j.JobDetail.JobDataMap["progress"]);
}

当然,您可以过滤 GetCurrentlyExecutingJobs 的结果。

此外,您可以将作业设置为“Durable”和“PersistJobDataAfterExecution”,因此在完成后,您可以通过“scheduler.GetJobDetail(.. ) 并随后访问其 JobDataMap

It is quite possible.

I would go with something like this.
In job:

public virtual void Execute(IJobExecutionContext context)
{
    int i = 0;
    while (i++ < 100)
    {
        context.JobDetail.JobDataMap["progress"] = i;
        Thread.Sleep(1000);
    }
}

In code that wants to retrieve progress:

var jobs = scheduler.GetCurrentlyExecutingJobs();
foreach (var j in jobs)
{
    Console.WriteLine("Progress of {0} is {1}", 
        j.JobDetail.Key, 
        j.JobDetail.JobDataMap["progress"]);
}

You can filter result of GetCurrentlyExecutingJobs, of course.

Also, you can set job to be Durable and PersistJobDataAfterExecution, so after it is done, you can retrieve its progress and anything else via scheduler.GetJobDetail(..) and accessing its JobDataMap afterwards.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文