【发布时间】:2016-11-17 10:09:33
【问题描述】:
我有一个应用程序,它使用 hangfire 为我做长时间运行的工作(我知道工作所花费的时间,而且总是大致相同),并且在我的 UI 中,我想估计某项工作的时间已经完成了。为此,我需要查询 hangfire 以了解作业在队列中的位置以及在其上工作的服务器数量。
我知道我可以通过
获得入队作业的数量(在“DEFAULT”队列中)public long JobsInQueue() {
var monitor = JobStorage.Current.GetMonitoringApi();
return monitor.EnqueuedCount("DEFAULT");
}
和服务器的数量由
public int HealthyServers() {
var monitor = JobStorage.Current.GetMonitoringApi();
return monitor.Servers().Count(n => (n.Heartbeat != null) && (DateTime.Now - n.Heartbeat.Value).TotalMinutes < 5);
}
(顺便说一句:我排除了较旧的心跳,因为如果我关闭服务器,它们有时会在 hangfire 数据库中徘徊。有更好的方法吗?),但要给出正确的估计,我需要知道工作在队列。我怎么得到它?
【问题讨论】:
-
另外,令我震惊的是,您应该将问题改写为“如何在 Hangfire 中估算工作完成时间”
-
@TomRedfern:谢谢,好主意。完成。