gpt4 book ai didi

javascript - 如何在一天中的特定时间调用函数?

转载 作者:行者123 更新时间:2023-12-04 07:25:51 26 4
gpt4 key购买 nike

我需要调用studentUpdateAttendanceStart在类(class)开始前 10 分钟采取行动 endDate .我怎样才能做到这一点?。下面的代码是我目前拥有的,但学生需要刷新页面。当我包括 allowAttendanceUpdateAfter , courseDocId , endDate , id , now , startDate , student , studentTimestamp , 和 studentUpdateAttendanceStart在 useEffect 的依赖数组内 useEffect因为我通过 now 被多次调用多变的。
我正在尝试做的 :
如果类(class)从上午 10:30 开始并在上午 11:30 结束,从上午 11:20 到上午 11:30,首先检查 student.attendanceStatus不为空,如果时间在上午 11:20 到上午 11:30 之间。然后检查学生是否已登录至少一定时间以将其标记为在场,否则将学生标记为缺席。最好的方法是什么?我目前拥有的代码有效,但学生需要刷新页面。

const now = moment().toDate(),
allowAttendanceUpdateAfter = moment(endDate).subtract(10, 'minutes');

useEffect(() => {
if (
now >= allowAttendanceUpdateAfter.toDate() &&
now <= endDate &&
!student.attendanceStatus.length
) {
if (allowAttendanceUpdateAfter - startDate < now - studentTimestamp) {
studentUpdateAttendanceStart(courseDocId, {
...student,
id,
attendanceStatus: 'Present'
});
} else {
studentUpdateAttendanceStart(courseDocId, {
...student,
id,
attendanceStatus: 'Absent'
});
}
}
}, []);

最佳答案

你需要一个 cron 工作。
无论您在何处托管此应用程序的 api,通常都会从容器中提供此类服务,您可以通过 http 或主机支持的任何其他通信方法向客户端发出特定时间的定期请求。

关于javascript - 如何在一天中的特定时间调用函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68219185/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com