Python 作业计划程序中未执行Web推送
正在执行作业计划程序,但由于某些原因,web推送未激活。我尝试在没有作业计划程序的情况下调用web推送功能,但它确实会在浏览器上触发通知。但是,当我在add_job scheduler函数中调用它时,不会触发任何内容。如果要激活web推送供参考,则应在作业计划程序之后调用GET提醒。请帮忙Python 作业计划程序中未执行Web推送,python,reactjs,flask,jobs,apscheduler,Python,Reactjs,Flask,Jobs,Apscheduler,正在执行作业计划程序,但由于某些原因,web推送未激活。我尝试在没有作业计划程序的情况下调用web推送功能,但它确实会在浏览器上触发通知。但是,当我在add_job scheduler函数中调用它时,不会触发任何内容。如果要激活web推送供参考,则应在作业计划程序之后调用GET提醒。请帮忙 这里定义了sched的位置,为什么您只在处理程序中启动它,而不是在应用程序启动时启动它?您可以尝试使用simple_scheduler来代替。。。 @app.route("/notificatio
这里定义了
sched
的位置,为什么您只在处理程序中启动它,而不是在应用程序启动时启动它?您可以尝试使用simple_scheduler来代替。。。
@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), message, VAPID_PRIVATE_KEY, 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