SELECT * FROM records WHERE notify_at = DATE(NOW())
你的cron可以存储在 /etc/cron.d 中
/etc/cron.d/send_reminders :
# run once a day at 1AM
0 1 * * * someuser /path/to/your/script
在脚本代码中,脚本的内容是您的逻辑,其中:
results = fetch_by_sql("SELECT * FROM records WHERE notify_at = DATE(NOW()) AND last_notified_at IS NULL");
foreach(results as record) {
send_email(record.recipient, "Your subject", "Your body");
/* mark the record as notified so we dont ever send multiple emails */
update_sql("UPDATE records SET last_notified_at = NOW() WHERE id = " + record.id);
}
1 回答
安排一天运行一次的cron,检查那天需要发送电子邮件的记录 .
想象一下,你有一个像
notify_at
这样的日期时间 - 那么你的cron基本上每天都会这样做SELECT * FROM records WHERE notify_at = DATE(NOW())
你的cron可以存储在
/etc/cron.d
中/etc/cron.d/send_reminders
:在脚本代码中,脚本的内容是您的逻辑,其中: