是否有办法在vibed中每天早上8:00运行任务?

是否有办法在vibed中每天早上8:00运行任务?,d,vibed,D,Vibed,我尝试每天早上8点在vibe.d web应用程序中运行一项任务。 目前,我使用setTimer函数,将周期参数设置为true。但这样,我无法准确控制任务触发的时间。在vibed中有没有一种简单的方法可以做到这一点?谢谢你,西格德,这正是我所做的。我计算到下一个早上8点的时间,然后调用setTimer。以下是代码供进一步参考: void startDailyTaskAtTime(TimeOfDay time, void delegate() task) { // Get the current

我尝试每天早上8点在vibe.d web应用程序中运行一项任务。
目前,我使用
setTimer
函数,将周期参数设置为
true
。但这样,我无法准确控制任务触发的时间。在vibed中有没有一种简单的方法可以做到这一点?

谢谢你,西格德,这正是我所做的。我计算到下一个早上8点的时间,然后调用setTimer。以下是代码供进一步参考:

void startDailyTaskAtTime(TimeOfDay time, void delegate() task) {
  // Get the current date and time
  DateTime now = cast(DateTime)Clock.currTime();

  // Get the next time occurrence
  DateTime nextOcc = cast(DateTime)now;
  if (now.timeOfDay >= time) {
    nextOcc += dur!"days"(1);
  }
  nextOcc.timeOfDay = time;

  // Get the duration before now and the next occurrence
  Duration timeBeforeNextOcc = nextOcc - now;

  void setDailyTask() {
    // Run the task once
    task(); 
    // Run the task all subsequent days at the same time
    setTimer(1.days, task, true);
  }

  setTimer(timeBeforeNextOcc, &setDailyTask);
}

没有任何东西阻止您计算时间直到下一个上午8:00,并以适当的持续时间调用
setTimer