问题描述
基于项目文档,在Java版本中存在一些基于cron的调度.但是我在.net实现中没有发现任何类似之处.
Based on the project documentation, there is in java version exists some cron-based scheduling. But i don't find any similar in .net implementation.
我的任务是每天更新一次缓存,以完成长期运行的工作.在这种情况下(.net版本没有内置的调度功能),我想到了创建应用程序,该应用程序将在客户端模式下运行并使用数据更新缓存.并使用Windows Task Scheduler运行此应用.
My task is to once per day update my cache with long running job. In this case (no build in scheduling features for .net version) i think of creating app, which will run ignite in client mode and update cache with data. And run this app with windows task scheduler.
有更好的解决方案吗?还是一个很好的例子?
Is there are a better solutions? Or maybe a good examples?
收到答案后实施的解决方案:
使用 FluentScheduler 安排定期作业.不幸的是,我打算使用的 HangFire 无效.如果包含当前正在执行的调度程序的节点由于某些原因发生故障或脱机,则服务将在其余节点之一上启动,并且不会丢失任何调度作业.
Used FluentScheduler for scheduling periodicaly jobs. Unfortunately the HangFire I intended to use did not work. If node, which contain current executing scheduler fails or gone ofline for some reasons, then service starts on one of the rest nodes, and no scheduling jobs will be lost.
调度员作业代码
public class CacheUpdateRegistry : Registry
{
private readonly IIgnite _ignite;
public CacheUpdateRegistry(IIgnite ignite)
{
_ignite = ignite;
// output to console current node id as example each 2 seconds
Schedule(() => Console.WriteLine("Recurring on node: + " + _ignite.GetCluster().GetLocalNode().Id)).ToRunNow().AndEvery(2).Seconds();
}
}
服务代码:
public class CacheUpdateSchedulerService : IService
{
[InstanceResource]
private readonly IIgnite _ignite;
public void Init(IServiceContext context)
{
Console.WriteLine("CacheUpdateSchedulerService initialized");
obManager.Initialize(new CacheUpdateRegistry(_ignite));
}
// other code removed for brevity
}
点燃节点代码:
var services = _ignite.GetServices();
services.DeployClusterSingleton("cacheUpdateScheduler", new CacheUpdateSchedulerService());
推荐答案
Java中的Ignite Scheduler API非常基本,并且仅在本地使用.实际上,它几乎与Ignite无关.
Ignite Scheduler API in Java is quite basic and local-only. It has almost nothing to do with Ignite, actually.
这就是为什么我们决定在.NET端省略此API:使用计时器类.
That's why we decided to omit this API on .NET side: same thing can be achieved with Timer class.
这篇关于apache点燃.net安排任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!