chunk when large reminder
All checks were successful
Lint and Format Check / lint-and-format (pull_request) Successful in 12s
All checks were successful
Lint and Format Check / lint-and-format (pull_request) Successful in 12s
This commit is contained in:
parent
7e13965f1c
commit
5816864066
1 changed files with 18 additions and 4 deletions
|
@ -202,8 +202,19 @@ export const setTimeoutReminder = (
|
||||||
option: OptionReminder,
|
option: OptionReminder,
|
||||||
timeout: number,
|
timeout: number,
|
||||||
) => {
|
) => {
|
||||||
return Number(
|
const setChunkedTimeout = (remainingTime: number) => {
|
||||||
setTimeout(() => {
|
// Maximum for setTimeout is Int32
|
||||||
|
if (remainingTime > 2147483647) {
|
||||||
|
// Schedule a 24-hour delay (24 * 60 * 60 * 1000), then check again
|
||||||
|
const dayChunk = 86400000;
|
||||||
|
|
||||||
|
return setTimeout(() => {
|
||||||
|
setChunkedTimeout(remainingTime - dayChunk);
|
||||||
|
}, dayChunk);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Final timeout when remaining time is within limit
|
||||||
|
return setTimeout(() => {
|
||||||
deleteReminder(client, String(info.createdAt), info.userId).then((val) => {
|
deleteReminder(client, String(info.createdAt), info.userId).then((val) => {
|
||||||
if (val != true) {
|
if (val != true) {
|
||||||
throw val;
|
throw val;
|
||||||
|
@ -211,8 +222,11 @@ export const setTimeoutReminder = (
|
||||||
|
|
||||||
sendReminder(client, info, option);
|
sendReminder(client, info, option);
|
||||||
});
|
});
|
||||||
}, timeout * 1000),
|
}, remainingTime);
|
||||||
);
|
};
|
||||||
|
|
||||||
|
// Convert to milliseconds
|
||||||
|
return Number(setChunkedTimeout(timeout * 1000));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue