[英]How to disable multiple axios.post?
function executeStatement() {
let time = global.setInterval(() => {
var date = new Date();
if (date.getHours() === 14 && date.getMinutes() === 38) {
console.log("What did it choose?", result_shuffle);
console.log("Time", time);
if (shufflearray) {
var sql = `UPDATE developers SET selected = ${result_shuffle.selected} + 1 WHERE id = ${result_shuffle.id}`;
db.query(sql, function (err, result) {
if (err) throw err;
console.log(result.affectedRows + " record(s) updated");
});
axios.post('https://hooks.slack.com/services/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', {
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: `Name: yo \n\n Email: sup`,
},
},
],
})
}
else {
const abort = "abort"
console.log(abort);
}
}
}, 2000);
};
So I'm building a function that executes a certain value when the timestamp 14:38 has hit.所以我正在构建一个 function,它在时间戳 14:38 命中时执行某个值。 This message is then redirected to a Slack channel (Slack bot basically).
然后将此消息重定向到 Slack 频道(基本上是 Slack 机器人)。 Everything works smoothly BUT I'm having a problem.
一切顺利,但我遇到了问题。 The axios.post is sending multiple POSTS.
axios.post 正在发送多个 POST。
So my slack channel is now being spammed with Name: Email: posts.所以我的松弛频道现在被垃圾邮件发送了 Name: Email: posts。
How can I make it so it only publishes once when the time hits?我怎样才能让它只在时间到了时发布一次? Or how can I make the time more precise so the axios.post will stop?
或者我怎样才能让时间更精确,这样 axios.post 就会停止?
You can modify your if statement something like this您可以像这样修改您的 if 语句
if (date.getHours() === 14 && date.getMinutes() === 38 && date.getSeconds() < 2) {
// ....
}
This will check for seconds as well这也将检查秒数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.