如何创建在石英中等待的触发器

发布于 2025-01-30 12:19:59 字数 630 浏览 3 评论 0原文

我创建了一个作业和一个触发器,

var jobKey = new JobKey("awesome job", "awesome group");
q.AddJob<HelloWorldJob>(jobKey, j => j
.WithDescription("my awesome job"));

q.AddTrigger(opts => opts
    .ForJob(jobKey)
    .WithIdentity("HelloWorldJob-trigger")
    .WithSimpleSchedule(x => x.WithIntervalInSeconds(5))

可以在这样的控制器中称呼它,

    var scheduler = await schedulerFactory.GetScheduler();

    await scheduler.TriggerJob(jobKey);

但是问题是在启动应用程序时开始作业

是否可以保持触发空闲?这样我稍后可以手动触发它?

我发现了一些类似的问题,建议将来将startat方法放在以后的日期,但是这个问题是旧的,也许有更合适的方法可以做到这一点?

I created a job and a trigger

var jobKey = new JobKey("awesome job", "awesome group");
q.AddJob<HelloWorldJob>(jobKey, j => j
.WithDescription("my awesome job"));

q.AddTrigger(opts => opts
    .ForJob(jobKey)
    .WithIdentity("HelloWorldJob-trigger")
    .WithSimpleSchedule(x => x.WithIntervalInSeconds(5))

I can call it in a controller like this

    var scheduler = await schedulerFactory.GetScheduler();

    await scheduler.TriggerJob(jobKey);

But the problem is that the job starts when application is started

Is there a way to keep trigger idle? so I can trigger it later manually?

I found some similar questions where it was suggested to put in StartAt method a date long in future, but this questions were old, maybe there is a more appropriate way of doing it?

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

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

发布评论

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

评论(1

心房敞 2025-02-06 12:19:59

不要添加触发器,请在要手动触发作业时调用iScheduler.triggerjob。将作业添加为Scheduler Init中的耐用性,因此它不需要触发器参考它。

Don't add a trigger, call IScheduler.TriggerJob when you want to manually trigger the job. Add the job as durable in scheduler init so it doesn't need to have triggers referring to it.

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