如何解决作业调度程序中未执行 Web 推送
正在执行作业调度程序,但由于某种原因未激活网络推送。我尝试在没有作业调度程序的情况下调用网络推送功能,但它确实在浏览器上触发了通知。但是,当我在 add_job 调度程序函数中调用它时,没有任何触发。如果要激活 Web 推送仅供参考,则应在作业调度程序之后调用 GET 提醒。请帮忙。
@app.route("/notification",methods = ['POST','PUT'])
@token_required
def setNotifications(current_user,token):
if request.method == 'POST':
form = json.loads(request.data.decode('UTF-8'))
subscription = form["subscription"]
subscriptionId = form["subscriptionId"]
dailyReminder = True if form['daily'] is True else False
weeklyReminder = True if form['weekly'] is True else False
yearlyReminder = True if form['yearly'] is True else False
createNotif = db.session.query(User).filter(User.id == current_user.id).first()
reminder = db.session.query(Reminder).filter(Reminder.subscriptionId == subscriptionId).first()
message = json.dumps({"token": token,"subscriptionId": subscriptionId})
# print("Printing message" + message)
vapid_CLAims = {
"sub": "my email"
}
if(createNotif.subscription == " "):
createNotif.subscription = json.dumps(subscription)
db.session.commit()
try:
# print("entering code")
sched.add_job(lambda:modules.send_web_push(json.loads(createNotif.subscription),message,vapid_PRIVATE_KEY,vapid_CLAims),'date',run_date = datetime.date(2021,5,8))
sched.start()
# modules.send_web_push(json.loads(createNotif.subscription),vapid_CLAims)
# print("started here",flush= True)
return jsonify({'success':1})
except Exception as e:
print("error",e)
print("Could not send notification",flush=True)
return jsonify({'Failed':str(e)})
if request.method == 'PUT':
removeSubscription = db.session.query(User).filter(User.id == current_user.id).first()
removeSubscription.subscription = " "
db.session.commit()
return jsonify({"success": "push notification has been updated"}),200
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。