Quartz.Net - 更新/删除作业/触发器

发布于 2024-11-24 19:39:31 字数 845 浏览 1 评论 0原文

我使用 Quartz 提取最新任务(从另一个来源),然后将其添加为作业,为每个任务创建触发器等。 - 简单的。

然而,有时任务会发生变化(因此它们已经存在)。因此我想更改它(让我们说保持简单Description。下面的代码使用给定日期更新特定任务的描述。

private static void SetLastPull(DateTime lastPullDateTime)
{
  var lastpull = sched.GetJobDetail("db_pull", "Settings");

  if(lastpull != null)
  {
    lastpull.Description = lastPullDateTime.ToString();
  }
  else
  {
    var newLastPull = new JobDetail("db_pull", "Settings", typeof(IJob));
    newLastPull.Description = lastPullDateTime.ToString();
    var newLastPullTrigger = new CronTrigger("db_pull", "Settings", "0 0 0 * 12 ? 2099");
    sched.ScheduleJob(newLastPull, newLastPullTrigger);
  }
}

我假设在我执行lastpull.Description = lastPullDateTime.ToString之后(); 我应该调用一些东西来保存对数据库的更改有没有办法在 Quartz 中做到这一点,或者我是否必须使用其他方式并更新它?

I'm using Quartz to pull latest tasks (from another source), it then adds it in as a job, creates triggers etc per each task. - Easy.

However, sometimes tasks change (therefore they already exist). Therefore I would like to change its (lets say to keep it simple Description. Code below updates specific task's description with given date.

private static void SetLastPull(DateTime lastPullDateTime)
{
  var lastpull = sched.GetJobDetail("db_pull", "Settings");

  if(lastpull != null)
  {
    lastpull.Description = lastPullDateTime.ToString();
  }
  else
  {
    var newLastPull = new JobDetail("db_pull", "Settings", typeof(IJob));
    newLastPull.Description = lastPullDateTime.ToString();
    var newLastPullTrigger = new CronTrigger("db_pull", "Settings", "0 0 0 * 12 ? 2099");
    sched.ScheduleJob(newLastPull, newLastPullTrigger);
  }
}

I'm assuming after I do lastpull.Description = lastPullDateTime.ToString(); I should call something to save changes to database. Is there a way to do it in Quartz or do I have to go to using other means and update it?

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

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

发布评论

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

评论(1

决绝 2024-12-01 19:39:31

作业一旦安排就无法更改(更新)。您只能重新安排它(进行任何您可能想要进行的更改)或删除它并创建一个新的。

You can't change (update) a job once it has been scheduled. You can only re-schedule it (with any changes you might want to make) or delete it and create a new one.

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