Chg: 全てのスケジュールが正確に動作するように

This commit is contained in:
2026-05-16 19:20:16 +09:00
parent 33435f4c46
commit 3a446440d3
8 changed files with 73 additions and 35 deletions
+5
View File
@@ -9,8 +9,13 @@ import unfollowCommand from "@/feature/command/unfollow";
import miqCommand from "@/feature/command/miq";
import initI18n from "@/lib/i18n";
import config from "@/lib/config";
import CronExpressionParser from "cron-parser";
await initI18n();
const next = BigInt(CronExpressionParser.parse(`*/${config.command.interval} * * * *`).next().getTime() * 1_000_000);
while (process.hrtime.bigint() > next) {}
console.log("コマンドの処理を行います");
try {
+17 -16
View File
@@ -1,25 +1,26 @@
import { createUeuse } from "@/lib/client";
import initI18n from "@/lib/i18n";
import CronExpressionParser from "cron-parser";
import { format } from "date-fns";
import i18next from "i18next";
import { parentPort } from "node:worker_threads";
await initI18n();
parentPort?.on("message", async () => {
console.log("新年迎春の投稿を行います");
const next = BigInt(CronExpressionParser.parse("0 0 1 1 *").next().getTime() * 1_000_000);
while (process.hrtime.bigint() > next) {}
try {
await createUeuse({
text: i18next.t("hnyNotice", { year: String(new Date().getFullYear()) }),
}, "新年迎春");
console.log("新年迎春の投稿を行います");
console.log("新年迎春投稿時刻:", format(new Date(), "yyyy/M/d H:mm:ss:SSS"));
process.exit(0);
} catch (err: any) {
console.error("message" in err
? err.message
: err);
process.exit(1);
}
});
try {
await createUeuse({
text: i18next.t("hnyNotice", { year: String(new Date().getFullYear()) }),
}, "新年迎春");
console.log("新年迎春投稿時刻:", format(new Date(), "yyyy/M/d H:mm:ss:SSS"));
process.exit(0);
} catch (err: any) {
console.error("message" in err
? err.message
: err);
process.exit(1);
}
+5
View File
@@ -1,9 +1,14 @@
import { createUeuse } from "@/lib/client";
import initI18n from "@/lib/i18n";
import CronExpressionParser from "cron-parser";
import { format } from "date-fns";
import i18next from "i18next";
await initI18n();
const next = BigInt(CronExpressionParser.parse("0 * * * *").next().getTime() * 1_000_000);
while (process.hrtime.bigint() > next) {}
console.log("時報の投稿を行います");
try {
+8
View File
@@ -2,6 +2,7 @@ import client from "@/lib/client";
import config from "@/lib/config";
import initI18n from "@/lib/i18n";
import Memory from "@/lib/memory";
import CronExpressionParser from "cron-parser";
import i18next from "i18next";
import { readFileSync } from "node:fs";
import { EOL } from "node:os";
@@ -63,6 +64,13 @@ if (
workerData.startsWith("scheduledWeatherNotice")
) {
await initI18n();
const cronStr = workerData.endsWith("Tomorrow")
? "0 18 * * *"
: "0 7 * * *"
const next = BigInt(CronExpressionParser.parse(cronStr).next().getTime() * 1_000_000);
while (process.hrtime.bigint() > next) {}
console.log("天気予報の投稿を行います");
try {
+13 -13
View File
@@ -31,34 +31,34 @@ try {
}
try {
schedule("0 * * * *", async () => {
schedule("56 59 * * * *", async () => {
new Worker(`${import.meta.dirname}/feature/timeNotice.js`);
});
schedule("0 7 * * *", async () => {
schedule("56 59 6 * * *", async () => {
new Worker(`${import.meta.dirname}/feature/weatherNotice.js`, {
workerData: "scheduledWeatherNotice",
});
});
schedule("0 18 * * *", async () => {
schedule("56 59 17 * * *", async () => {
new Worker(`${import.meta.dirname}/feature/weatherNotice.js`, {
workerData: "scheduledWeatherNoticeTomorrow",
});
});
schedule(`*/${config.command.interval} * * * *`, async () => {
const interval = config.command.interval;
const targetMinutes = [];
for (let i = interval - 1; i < 60; i += interval) {
targetMinutes.push(i);
}
const minutesStr = targetMinutes.join(",");
schedule(`56 ${minutesStr} * * * *`, async () => {
new Worker(`${import.meta.dirname}/feature/command/index.js`);
});
let hnyWorker: Worker | undefined = undefined;
schedule("57 59 23 31 12 *", () => {
hnyWorker = new Worker(`${import.meta.dirname}/feature/hnyNotice.js`);
});
schedule("0 0 0 1 1 *", () => {
hnyWorker?.postMessage("");
schedule("56 59 23 31 12 *", () => {
new Worker(`${import.meta.dirname}/feature/hnyNotice.js`);
});
} catch (err: any) {
console.error("message" in err