英文:
Hangfire how to retrieve and display all stored jobs?
问题
以下是翻译好的部分:
[HttpGet("jobs")]
[ProducesResponseType(StatusCodes.Status200OK)]
public IActionResult GetJobs()
{
var monitoringApi = JobStorage.Current.GetMonitoringApi();
var jobDetails = monitoringApi.EnqueuedJobs();
var response = new List<object>();
foreach (var job in jobDetails)
{
response.Add(new
{
JobId = job.Key,
JobName = job.Value.Job.Type.FullName,
EnqueuedAt = job.Value.EnqueuedAt,
State = job.Value.State
});
}
return Ok(response);
}
如果您需要进一步的帮助,请告诉我。
英文:
How to retrieve and display all stored jobs with on hangfire without UI?
This was one of my first tries:
[HttpGet("jobs")]
[ProducesResponseType(StatusCodes.Status200OK)]
public IActionResult GetJobs()
{
var monitoringApi = JobStorage.Current.GetMonitoringApi();
var jobDetails = monitoringApi.EnqueuedJobs();
var response = new List<object>();
foreach (var job in jobDetails)
{
response.Add(new
{
JobId = job.Key,
JobName = job.Value.Job.Type.FullName,
EnqueuedAt = job.Value.EnqueuedAt,
State = job.Value.State
});
}
return Ok(response);
}
答案1
得分: 1
选项 #1 - 使用 MonitoringApi
您已经尝试过这个方法,但您必须使用此链接接口逐个获取每个作业列表(已调度、处理中、成功等)。
不幸的是,没有简单的方法来获取所有内容,因为 Hangfire 将每个作业状态定义为不同的类,没有共同的基类(例如,EnqueuedJobDto
和 ScheduledJobDto
没有共同的基类)。
选项 #2 - 直接从您的数据库中获取信息
相当明了,但这可能取决于您在 Hangfire 中使用的存储方式。
英文:
Option #1 - Use the MonitoringApi
You've already tried this, but you'll have to get each job list individually (scheduled, processing, succeeded, etc.) by using this interface.
Unfortunately, there isn't a simple way of making some generic method that retrieves everything, since Hangfire defines each job state as a different class with no common base (e.g. EnqueuedJobDto
and ScheduledJobDto
share no base class).
Option #2 - Get the information straight from your database
Pretty self explanatory, but it might depend on the storage you're using for Hangfire.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论