我正在尝试向用户发送推送通知并尝试每天发送 3 次或 2 次,但之后我不想发送通知,就像我今天发送了 3 次通知一样,之后也不想发送通知下一个周期从第二天开始,依此类推,我在晚上 7 点之后无法停止,我想在晚上 7 点之后停止节点 cron 并在第二天开始循环。
const cron = require("node-cron");
const { db, growthfile20724db } = require("../constant");
let AWS = require("aws-sdk");
// const { getAuth } = require('../utils/reportUtils');
AWS.config.update({
accessKeyId: "",
secretAccessKey: "",
region: "us-east-1",
});
const sns = new AWS.SNS();
const sendReminderRet = async (profile) => {
console.log(profile);
const updateSnapshot = await db
.collection("Updates")
.where("phoneNumber", "==", profile.phoneNumber)
.get();
const updateArray = updateSnapshot.docs.map(
(doc) => doc.data().registrationToken
);
console.log("registerToken", updateArray[0]);
cron.schedule("* * /3 * * *", () => {
console.log("running a task every ten minutes");
let params = {
PlatformApplicationArn: "",
Token: `${updateArray[0]}`,
};
let payload2 = JSON.stringify({
default: "push notification",
GCM: JSON.stringify({
notification: {
body: "Hi ",
title: "Reminder",
},
// data: {
// testdata: "Check out these awesome deals!",
// url: "www.amazon.com",
// },
}),
});
sns.createPlatformEndpoint(params, (err, data) => {
if (err) {
console.log(err);
} else {
sns.publish(
{
Message: payload2, // Required
MessageStructure: "json",
TargetArn: data.EndpointArn,
},
(err, data) => {
if (err) {
console.log(err.stack);
} else {
console.log(data);
}
}
);
}
});
});
};
module.exports = { sendReminderRet };