作业调度程序中未执行 Web 推送

问题描述

正在执行作业调度程序,但由于某种原因未激活网络推送。我尝试在没有作业调度程序的情况下调用网络推送功能,但它确实在浏览器上触发了通知。但是,当我在 add_job 调度程序函数调用它时,没有任何触发。如果要激活 Web 推送仅供参考,则应在作业调度程序之后调用 GET 提醒。请帮忙。

enter image description here

@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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...